Skip to content

Commit

Permalink
refactor: Optimize common library module[747950]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Nov 11, 2022
1 parent 0b10607 commit 6479eec
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 63 deletions.
6 changes: 3 additions & 3 deletions TTKCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 2.8.11)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
cmake_policy(SET CMP0028 OLD)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
cmake_policy(SET CMP0028 OLD)
endif(COMMAND cmake_policy)

add_definitions(-DQT_NO_DEBUG)
Expand Down
5 changes: 3 additions & 2 deletions TTKCommon/TTKCommon.pri
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ win32{
QT += xml
msvc{
HEADERS += \
$$PWD/TTKLibrary/ttkabstractmovedialog.h \
$$PWD/TTKLibrary/ttkabstractmovedialog.h \
$$PWD/TTKLibrary/ttkabstractmoveresizewidget.h \
$$PWD/TTKLibrary/ttkabstractmovewidget.h \
Expand All @@ -39,6 +38,8 @@ win32{
$$PWD/TTKLibrary/ttkdesktopwrapper.h \
$$PWD/TTKLibrary/ttkglobalhelper.h \
$$PWD/TTKLibrary/ttksemaphoreloop.h \
$$PWD/TTKLibrary/ttktime.h
$$PWD/TTKLibrary/ttksuperenum.h \
$$PWD/TTKLibrary/ttktime.h \
$$PWD/TTKLibrary/ttktoastlabel.h
}
}
29 changes: 14 additions & 15 deletions TTKCommon/TTKDumper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ cmake_minimum_required(VERSION 2.8.11)
project(TTKDumper)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
cmake_policy(SET CMP0028 OLD)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
cmake_policy(SET CMP0028 OLD)
endif(COMMAND cmake_policy)

add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_THREAD)

set(MUSIC_HEADERS
ttkdumper.h
miniprocess.h
)
ttkdumper.h
miniprocess.h
)

set(MUSIC_SOURCES
ttkdumper.cpp
miniprocess.cpp
)
ttkdumper.cpp
miniprocess.cpp
)

if(WIN32)
list(APPEND MUSIC_SOURCES ${PROJECT_NAME}.rc)
list(APPEND MUSIC_SOURCES ${PROJECT_NAME}.rc)
endif()

if(TTK_QT_VERSION VERSION_GREATER "4")
Expand All @@ -36,10 +36,10 @@ if(TTK_QT_VERSION VERSION_GREATER "4")

set(QT5_LIBS Qt5::Core)
if(WIN32)
list(APPEND QT5_LIBS -lpsapi)
list(APPEND QT5_LIBS -lpsapi)
endif()

target_link_libraries(${PROJECT_NAME} ${QT5_LIBS})

else()
QT4_WRAP_CPP(MUSIC_MOC_H ${MUSIC_HEADERS})

Expand All @@ -51,9 +51,8 @@ else()

set(QT4_LIBS ${QT_QTCORE_LIBRARY})
if(WIN32)
list(APPEND QT4_LIBS -lpsapi)
list(APPEND QT4_LIBS -lpsapi)
endif()
target_link_libraries(${PROJECT_NAME} ${QT4_LIBS})

target_link_libraries(${PROJECT_NAME} ${QT4_LIBS})
endif()

77 changes: 38 additions & 39 deletions TTKCommon/TTKLibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,57 @@ cmake_minimum_required(VERSION 2.8.11)
project(TTKLibrary)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
cmake_policy(SET CMP0028 OLD)
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0005 OLD)
cmake_policy(SET CMP0028 OLD)
endif(COMMAND cmake_policy)

add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_THREAD)

set(MUSIC_HEADERS
ttkabstractmovedialog.h
ttkabstractmoveresizewidget.h
ttkabstractmovewidget.h
ttkabstractresizeinterface.h
ttkabstractthread.h
ttkabstractxml.h
ttkclickedgroup.h
ttkclickedlabel.h
ttkclickedslider.h
ttkcryptographichash.h
ttkdesktopwrapper.h
ttkglobalhelper.h
ttksemaphoreloop.h
ttksuperenum.h
ttktime.h
)
ttkabstractmovedialog.h
ttkabstractmoveresizewidget.h
ttkabstractmovewidget.h
ttkabstractresizeinterface.h
ttkabstractthread.h
ttkabstractxml.h
ttkclickedgroup.h
ttkclickedlabel.h
ttkclickedslider.h
ttkcryptographichash.h
ttkdesktopwrapper.h
ttkglobalhelper.h
ttksemaphoreloop.h
ttksuperenum.h
ttktime.h
ttktoastlabel.h
)

set(MUSIC_SOURCES
ttkabstractmovedialog.cpp
ttkabstractmoveresizewidget.cpp
ttkabstractmovewidget.cpp
ttkabstractthread.cpp
ttkabstractxml.cpp
ttkclickedgroup.cpp
ttkclickedlabel.cpp
ttkclickedslider.cpp
ttkcryptographichash.cpp
ttkdesktopwrapper.cpp
ttkglobalhelper.cpp
ttksemaphoreloop.cpp
ttksuperenum.cpp
ttktime.cpp
)
ttkabstractmovedialog.cpp
ttkabstractmoveresizewidget.cpp
ttkabstractmovewidget.cpp
ttkabstractthread.cpp
ttkabstractxml.cpp
ttkclickedgroup.cpp
ttkclickedlabel.cpp
ttkclickedslider.cpp
ttkcryptographichash.cpp
ttkdesktopwrapper.cpp
ttkglobalhelper.cpp
ttksemaphoreloop.cpp
ttksuperenum.cpp
ttktime.cpp
ttktoastlabel.cpp
)

SET(MUSIC_QRC
${PROJECT_NAME}.qrc
${PROJECT_NAME}.qrc
)

if(WIN32)
list(APPEND MUSIC_SOURCES ${PROJECT_NAME}.rc)
list(APPEND MUSIC_SOURCES ${PROJECT_NAME}.rc)
endif()

if(TTK_QT_VERSION VERSION_GREATER "4")
Expand All @@ -66,7 +68,6 @@ if(TTK_QT_VERSION VERSION_GREATER "4")

set(QT5_LIBS Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} ${QT5_LIBS})

else()
QT4_WRAP_CPP(MUSIC_MOC_H ${MUSIC_HEADERS})
QT4_ADD_RESOURCES(MUSIC_RCC_SRCS ${MUSIC_QRC})
Expand All @@ -79,6 +80,4 @@ else()

set(QT4_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${QT4_LIBS})

endif()

6 changes: 4 additions & 2 deletions TTKCommon/TTKLibrary/TTKLibrary.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ HEADERS += \
$$PWD/ttkglobalhelper.h \
$$PWD/ttksemaphoreloop.h \
$$PWD/ttksuperenum.h \
$$PWD/ttktime.h
$$PWD/ttktime.h \
$$PWD/ttktoastlabel.h

SOURCES += \
$$PWD/ttkabstractmovedialog.cpp \
Expand All @@ -84,7 +85,8 @@ SOURCES += \
$$PWD/ttkglobalhelper.cpp \
$$PWD/ttksemaphoreloop.cpp \
$$PWD/ttksuperenum.cpp \
$$PWD/ttktime.cpp
$$PWD/ttktime.cpp \
$$PWD/ttktoastlabel.cpp

RESOURCES += $$PWD/TTKLibrary.qrc

Expand Down
4 changes: 2 additions & 2 deletions TTKCommon/TTKLibrary/ttktime.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class TTK_MODULE_EXPORT TTKTime

inline friend QDataStream& operator<<(QDataStream &stream, const TTKTime &other)
{
stream << other.day() << other.hour() << other.minute()
<< other.second() << other.millionSecond();
stream << other.day() << " " << other.hour() << " " << other.minute() << " "
<< other.second() << " " << other.millionSecond();
return stream;
}

Expand Down
100 changes: 100 additions & 0 deletions TTKCommon/TTKLibrary/ttktoastlabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "ttktoastlabel.h"
#include "ttkdesktopwrapper.h"
#include "ttknumberdefine.h"

#include <QPainter>
#include <QPropertyAnimation>

TTKToastLabel::TTKToastLabel(QWidget *parent)
: QLabel(parent),
m_font(font())
{
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_DeleteOnClose);

setFontSize(15);
setFontMargin(20, 20);

connect(&m_timer, SIGNAL(timeout()), SLOT(closeAnimation()));
m_timer.setInterval(MT_S2MS);
m_timer.start();
}

TTKToastLabel::TTKToastLabel(const QString &text, QWidget *parent)
: TTKToastLabel(parent)
{
setText(text);
}

TTKToastLabel::~TTKToastLabel()
{
m_timer.stop();
}

void TTKToastLabel::setFontMargin(int height, int width)
{
m_margin.setX(height);
m_margin.setY(width);
}

int TTKToastLabel::timerInterval() const
{
return m_timer.interval();
}

void TTKToastLabel::setFontSize(int size)
{
m_font.setPointSize(size);
setFont(m_font);
}

void TTKToastLabel::popup(QWidget *parent)
{
if(!parent)
{
const QSize &windowSize = TTKDesktopWrapper::screenGeometry().size();
move((windowSize.width() - width()) / 2, windowSize.height() - 200);
}
else
{
const QPoint &globalPoint = parent->mapToGlobal(QPoint(0, 0));
move(globalPoint.x() + (parent->width() - width()) / 2, globalPoint.y() + (parent->height() - height()) / 2);
}
show();
}

void TTKToastLabel::setText(const QString &text)
{
QFontMetrics ft(m_font);
setFixedSize(QtFontWidth(ft, text) + m_margin.x(), ft.height() + m_margin.y());
QLabel::setText(text);
}

void TTKToastLabel::closeAnimation()
{
m_timer.stop();

QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity", this);
animation->setDuration(MT_S2MS);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();

connect(animation, SIGNAL(finished()), SLOT(close()));
connect(animation, SIGNAL(finished()), SIGNAL(finished()));
}

void TTKToastLabel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(0, 0, 0, 175));
QtDrawRoundedRect(&painter, rect(), 6, 6);

painter.setPen(QColor(255, 255, 255));
painter.drawText(rect(), Qt::AlignCenter, text());
}
Loading

0 comments on commit 6479eec

Please sign in to comment.