diff --git a/ccheckbox.cpp b/ccheckbox.cpp new file mode 100644 index 0000000..5fd74a9 --- /dev/null +++ b/ccheckbox.cpp @@ -0,0 +1,28 @@ +#include "ccheckbox.h" + +#include + + +cCheckBox::cCheckBox(const QString &text, QWidget *parent) : + QCheckBox(text, parent) +{ + this->setMouseTracking(true); + this->setAttribute(Qt::WA_Hover); +} + +cCheckBox::cCheckBox(QWidget *parent) : + QCheckBox(parent) +{ + this->setMouseTracking(true); + this->setAttribute(Qt::WA_Hover); +} + +void cCheckBox::enterEvent(QEvent* /*ev*/) +{ + emit(windowEntered()); +} + +void cCheckBox::leaveEvent(QEvent* /*ev*/) +{ + emit(windowLeft()); +} diff --git a/ccheckbox.h b/ccheckbox.h new file mode 100644 index 0000000..83e1bb4 --- /dev/null +++ b/ccheckbox.h @@ -0,0 +1,26 @@ +#ifndef CCHECKBOX_H +#define CCHECKBOX_H + + +#include +#include + + +class cCheckBox : public QCheckBox +{ + Q_OBJECT + +public: + cCheckBox(const QString &text, QWidget *parent = nullptr); + cCheckBox(QWidget *parent = nullptr); + +protected: + void enterEvent(QEvent *ev) override; + void leaveEvent(QEvent *ev) override; + +signals: + void windowEntered(); + void windowLeft(); +}; + +#endif // CCHECKBOX_H diff --git a/cfontview.cpp b/cfontview.cpp index 4866e2d..7abcc24 100644 --- a/cfontview.cpp +++ b/cfontview.cpp @@ -1,6 +1,8 @@ #include "cfontview.h" #include "ui_cfontview.h" +#include "common.h" + #include @@ -14,7 +16,15 @@ cFontView::cFontView(QWidget *parent) : this->setAttribute(Qt::WA_Hover); QPalette palette = this->palette(); - m_defaultColor = palette.color(this->backgroundRole()); +// m_defaultColor = palette.color(this->backgroundRole()); + m_defaultColor = palette.color(QPalette::Window); + m_selectedColor = palette.color(QPalette::Highlight); + + connect(ui->m_lpFontName, &cCheckBox::windowEntered, this, &cFontView::windowEntered); + connect(ui->m_lpFontName, &cCheckBox::windowLeft, this, &cFontView::windowLeft); + + connect(ui->m_lpSampleText, &cLabel::windowEntered, this, &cFontView::windowEntered); + connect(ui->m_lpSampleText, &cLabel::windowLeft, this, &cFontView::windowLeft); } cFontView::~cFontView() @@ -51,23 +61,31 @@ void cFontView::setColor() QString background; if(m_foregroundColor.isValid()) - foreground = QString("color: rgba(%1, %2, %3, %4); ").arg(m_foregroundColor.red()).arg(m_foregroundColor.green()).arg(m_foregroundColor.blue()).arg(255); + foreground = "color: " + color2rgba(m_foregroundColor) + "; "; if(m_backgroundColor.isValid()) - background = QString("background-color: rgba(%1, %2, %3, %4); ").arg(m_backgroundColor.red()).arg(m_backgroundColor.green()).arg(m_backgroundColor.blue()).arg(255); + background = "background-color: " + color2rgba(m_backgroundColor) + "; "; if(!foreground.isEmpty() || !background.isEmpty()) ui->m_lpSampleText->setStyleSheet("QLabel { " + foreground + background + " }"); } -void cFontView::mouseMoveEvent(QMouseEvent* event) +void cFontView::enterEvent(QEvent* /*ev*/) { -qDebug() << event->type(); - - if(event->type() == QEvent::Enter) - ui->m_lpSampleText->setStyleSheet(QString("QLabel { background-color: rgba(0, 0, 255, 255); }")); - else if(event->type() == QEvent::Leave) - ui->m_lpSampleText->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, %4); }").arg(m_defaultColor.red()).arg(m_defaultColor.green()).arg(m_defaultColor.blue()).arg(255)); - - event->accept(); + windowEntered(); +} + +void cFontView::leaveEvent(QEvent* /*ev*/) +{ + windowLeft(); +} + +void cFontView::windowEntered() +{ + ui->m_lpFontName->setStyleSheet("QCheckBox { background-color: " + color2rgba(m_selectedColor) + "; }"); +} + +void cFontView::windowLeft() +{ + ui->m_lpFontName->setStyleSheet("QCheckBox { background-color: " + color2rgba(m_defaultColor) + "; }"); } diff --git a/cfontview.h b/cfontview.h index 6e5041e..7f74143 100644 --- a/cfontview.h +++ b/cfontview.h @@ -29,11 +29,17 @@ private: QColor m_backgroundColor; QColor m_foregroundColor; QColor m_defaultColor; + QColor m_selectedColor; void setColor(); protected: - void mouseMoveEvent(QMouseEvent* event) override; + void enterEvent(QEvent *ev) override; + void leaveEvent(QEvent *ev) override; + +public slots: + void windowEntered(); + void windowLeft(); }; #endif // CFONTVIEW_H diff --git a/cfontview.ui b/cfontview.ui index 60a6ac5..b7a0dad 100644 --- a/cfontview.ui +++ b/cfontview.ui @@ -6,14 +6,14 @@ 0 0 - 400 + 508 300 Form - + 0 @@ -51,24 +51,27 @@ 0 - - - 9 - - - 0 - - - + + + + + + 1 + 0 + + - Lore Ipsum + - - + + + + QFrame::Box + - + Lore Ipsum @@ -79,6 +82,18 @@ + + + cCheckBox + QCheckBox +
ccheckbox.h
+
+ + cLabel + QLabel +
clabel.h
+
+
diff --git a/clabel.cpp b/clabel.cpp new file mode 100644 index 0000000..0dd08d7 --- /dev/null +++ b/clabel.cpp @@ -0,0 +1,28 @@ +#include "clabel.h" + +#include + + +cLabel::cLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) : + QLabel(text, parent, f) +{ + this->setMouseTracking(true); + this->setAttribute(Qt::WA_Hover); +} + +cLabel::cLabel(QWidget *parent, Qt::WindowFlags f) : + QLabel(parent, f) +{ + this->setMouseTracking(true); + this->setAttribute(Qt::WA_Hover); +} + +void cLabel::enterEvent(QEvent* /*ev*/) +{ + emit(windowEntered()); +} + +void cLabel::leaveEvent(QEvent* /*ev*/) +{ + emit(windowLeft()); +} diff --git a/clabel.h b/clabel.h new file mode 100644 index 0000000..4636f22 --- /dev/null +++ b/clabel.h @@ -0,0 +1,26 @@ +#ifndef CLABEL_H +#define CLABEL_H + + +#include +#include + + +class cLabel : public QLabel +{ + Q_OBJECT + +public: + cLabel(const QString &text, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + cLabel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + +protected: + void enterEvent(QEvent *ev) override; + void leaveEvent(QEvent *ev) override; + +signals: + void windowEntered(); + void windowLeft(); +}; + +#endif // CLABEL_H diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 2bad0ff..083be1d 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -16,8 +16,8 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : initUI(); createActions(); - m_fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\a song for jennifer.ttf"); - m_fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\Grunge Handwriting.ttf"); +// m_fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\a song for jennifer.ttf"); +// m_fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\Grunge Handwriting.ttf"); QStringList families = m_fontDatabase.families(); diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..c90cf24 --- /dev/null +++ b/common.cpp @@ -0,0 +1,7 @@ +#include "common.h" + + +QString color2rgba(const QColor& color) +{ + return(QString("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(255)); +} diff --git a/common.h b/common.h new file mode 100644 index 0000000..478db79 --- /dev/null +++ b/common.h @@ -0,0 +1,12 @@ +#ifndef COMMON_H +#define COMMON_H + + +#include +#include + + +QString color2rgba(const QColor& color); + + +#endif // COMMON_H diff --git a/fontManager.pro b/fontManager.pro index 887832f..49327a5 100644 --- a/fontManager.pro +++ b/fontManager.pro @@ -23,14 +23,20 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\" #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + ccheckbox.cpp \ cfontview.cpp \ + clabel.cpp \ + common.cpp \ csplashscreen.cpp \ main.cpp \ cmainwindow.cpp HEADERS += \ + ccheckbox.h \ cfontview.h \ + clabel.h \ cmainwindow.h \ + common.h \ csplashscreen.h FORMS += \