Skip to content

Commit

Permalink
refactor: Optimize toast module[013288]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Nov 11, 2022
1 parent 5d829cd commit 95f7dda
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 222 deletions.
60 changes: 5 additions & 55 deletions TTKExample/Label/toastLabel/ttktoastlabelproperty.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ttktoastlabelproperty.h"
#include "ttktoastlabel.h"
#include "ttktoastlabel2.h"

#include <QToolButton>

Expand All @@ -9,13 +9,13 @@ TTKToastLabelProperty::TTKToastLabelProperty(QWidget *parent)
m_item = new QToolButton(this);
connect(m_item, SIGNAL(clicked()), SLOT(showWidget()));
//
m_label = new TTKToastLabel(this);
m_label = new TTKToastLabel2(this);
//
QtProperty *objectItem = m_groupManager->addProperty("QObject");
//
QtProperty *classNameItem = m_stringManager->addProperty("ClassName");
objectItem->addSubProperty(classNameItem);
m_stringManager->setValue(classNameItem, TTKObject_cast(TTKToastLabel*, m_label)->className());
m_stringManager->setValue(classNameItem, TTKObject_cast(TTKToastLabel2*, m_label)->className());
m_stringManager->setReadOnly(classNameItem, true);
//
QtProperty *activityItem = m_boolManager->addProperty("Activity");
Expand All @@ -24,74 +24,24 @@ TTKToastLabelProperty::TTKToastLabelProperty(QWidget *parent)
QtProperty *geometryItem = m_rectManager->addProperty("Geometry");
objectItem->addSubProperty(geometryItem);
//
QtProperty *fontMarginItem = m_sizeManager->addProperty("FontMargin");
m_sizeManager->setMinimum(fontMarginItem, QSize(0, 0));
m_sizeManager->setValue(fontMarginItem, QSize(20, 20));
objectItem->addSubProperty(fontMarginItem);
//
QtProperty *fontSizeItem = m_intManager->addProperty("FontSize");
m_intManager->setMinimum(fontSizeItem, 0);
m_intManager->setValue(fontSizeItem, 15);
objectItem->addSubProperty(fontSizeItem);
//
QtProperty *boldtem = m_boolManager->addProperty("Bold");
m_boolManager->setValue(boldtem, false);
objectItem->addSubProperty(boldtem);
//
QtProperty *intervalItem = m_intManager->addProperty("Interval");
m_intManager->setMinimum(intervalItem, 0);
m_intManager->setValue(intervalItem, 1500);
objectItem->addSubProperty(intervalItem);
//
QtProperty *textItem = m_stringManager->addProperty("Text");
m_stringManager->setValue(textItem, "Hello word");
objectItem->addSubProperty(textItem);
//
m_browser->addProperty(objectItem);
}

void TTKToastLabelProperty::boolPropertyChanged(QtProperty *property, bool value)
{
TTKToastLabel *widget = TTKObject_cast(TTKToastLabel*, m_label);
if(property->propertyName() == "Bold")
{
widget->setBold(value);
}
}

void TTKToastLabelProperty::intPropertyChanged(QtProperty *property, int value)
{
TTKToastLabel *widget = TTKObject_cast(TTKToastLabel*, m_label);
if(property->propertyName() == "FontSize")
{
widget->setFontSize(value);
}
else if(property->propertyName() == "Interval")
{
widget->setTimerInterval(value);
}
}

void TTKToastLabelProperty::stringPropertyChanged(QtProperty *property, const QString &value)
{
TTKToastLabel *widget = TTKObject_cast(TTKToastLabel*, m_label);
TTKToastLabel2 *widget = TTKObject_cast(TTKToastLabel2*, m_label);
if(property->propertyName() == "Text")
{
widget->setText(value);
}
}

void TTKToastLabelProperty::sizePropertyChanged(QtProperty *property, const QSize &value)
{
TTKToastLabel *widget = TTKObject_cast(TTKToastLabel*, m_label);
if(property->propertyName() == "FontMargin")
{
widget->setFontMargin(value.width(), value.height());
}
}

void TTKToastLabelProperty::showWidget()
{
TTKToastLabel *widget = TTKObject_cast(TTKToastLabel*, m_label);
TTKToastLabel2 *widget = TTKObject_cast(TTKToastLabel2*, m_label);
widget->popup(m_containItem);
}
3 changes: 0 additions & 3 deletions TTKExample/Label/toastLabel/ttktoastlabelproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ class TTK_MODULE_EXPORT TTKToastLabelProperty : public TTKWidgetProperty
explicit TTKToastLabelProperty(QWidget *parent = nullptr);

private Q_SLOTS:
virtual void boolPropertyChanged(QtProperty *property, bool value) override final;
virtual void intPropertyChanged(QtProperty *property, int value) override final;
virtual void stringPropertyChanged(QtProperty *property, const QString &value) override final;
virtual void sizePropertyChanged(QtProperty *property, const QSize &value) override final;

private Q_SLOTS:
void showWidget();
Expand Down
2 changes: 1 addition & 1 deletion TTKExample/TTKExample.pro
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ HEADERS += \
$$PWD/../TTKModule/Label/marqueeLabel/ttkmarqueelabel.h \
$$PWD/../TTKModule/Label/roundAnimationLabel/ttkroundanimationlabel.h \
$$PWD/../TTKModule/Label/splitItemLabel/ttksplititemlabel.h \
$$PWD/../TTKModule/Label/toastLabel/ttktoastlabel.h \
$$PWD/../TTKModule/Label/toastLabel/ttktoastlabel2.h \
$$PWD/../TTKModule/Label/transitionAnimationLabel/ttktransitionanimationlabel.h \
$$PWD/../TTKModule/Label/cloudPanelLabel/ttkcloudpanellabel.h \
$$PWD/../TTKModule/Label/barRulerLabel/ttkbarrulerlabel.h \
Expand Down
4 changes: 2 additions & 2 deletions TTKModule/Label/toastLabel/ToastLabel.pri
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

INCLUDEPATH += $$PWD

HEADERS += $$PWD/ttktoastlabel.h
HEADERS += $$PWD/ttktoastlabel2.h

SOURCES += $$PWD/ttktoastlabel.cpp
SOURCES += $$PWD/ttktoastlabel2.cpp
124 changes: 0 additions & 124 deletions TTKModule/Label/toastLabel/ttktoastlabel.cpp

This file was deleted.

19 changes: 19 additions & 0 deletions TTKModule/Label/toastLabel/ttktoastlabel2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "ttktoastlabel2.h"

TTKToastLabel2::TTKToastLabel2(QWidget *parent)
: TTKToastLabel(parent)
{
setAttribute(Qt::WA_QuitOnClose, false);
setAttribute(Qt::WA_DeleteOnClose, false);
}

TTKToastLabel2::TTKToastLabel2(const QString &text, QWidget *parent)
: TTKToastLabel(text, parent)
{

}

TTKToastLabel2::~TTKToastLabel2()
{

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TTKTOASTLABEL_H
#define TTKTOASTLABEL_H
#ifndef TTKTOASTLABEL2_H
#define TTKTOASTLABEL2_H

/***************************************************************************
* This file is part of the TTK Widget Tools project
Expand All @@ -19,48 +19,20 @@
* with this program; If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/

#include <QLabel>
#include <QTimer>
#include "ttkglobaldefine.h"
#include "ttktoastlabel.h"

/*!
* @author Greedysky <[email protected]>
*/
class TTK_MODULE_EXPORT TTKToastLabel : public QLabel
class TTK_MODULE_EXPORT TTKToastLabel2 : public TTKToastLabel
{
Q_OBJECT
TTK_DECLARE_MODULE(TTKToastLabel)
TTK_DECLARE_MODULE(TTKToastLabel2)
public:
explicit TTKToastLabel(QWidget *parent = nullptr);
explicit TTKToastLabel(const QString &text, QWidget *parent = nullptr);
~TTKToastLabel();

void setFontMargin(int height, int width);

void setTimerInterval(int msecond);
int timerInterval() const;

void setFontSize(int size);
int fontSize() const;

void setBold(bool bold);
bool bold() const;

void popup(QWidget *parent);

public Q_SLOTS:
void setText(const QString &text);

private Q_SLOTS:
void updateRender();

private:
virtual void paintEvent(QPaintEvent *event) override final;

QTimer m_timer;
QFont m_font;
QPoint m_margin;
explicit TTKToastLabel2(QWidget *parent = nullptr);
explicit TTKToastLabel2(const QString &text, QWidget *parent = nullptr);
~TTKToastLabel2();

};

#endif // TTKTOASTLABEL_H
#endif // TTKTOASTLABEL2_H

0 comments on commit 95f7dda

Please sign in to comment.