initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include "ccheckbox.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#ifndef CCHECKBOX_H
|
||||
#define CCHECKBOX_H
|
||||
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
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
|
||||
+30
-12
@@ -1,6 +1,8 @@
|
||||
#include "cfontview.h"
|
||||
#include "ui_cfontview.h"
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
@@ -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) + "; }");
|
||||
}
|
||||
|
||||
+7
-1
@@ -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
|
||||
|
||||
+30
-15
@@ -6,14 +6,14 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>508</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -51,24 +51,27 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
|
||||
<property name="horizontalSpacing">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="m_lpSampleText">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="cCheckBox" name="m_lpFontName">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Lore Ipsum</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="m_lpFontName">
|
||||
<item>
|
||||
<widget class="cLabel" name="m_lpSampleText">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>Lore Ipsum</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -79,6 +82,18 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>cCheckBox</class>
|
||||
<extends>QCheckBox</extends>
|
||||
<header>ccheckbox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>cLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>clabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#include "clabel.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CLABEL_H
|
||||
#define CLABEL_H
|
||||
|
||||
|
||||
#include <QLabel>
|
||||
#include <QEvent>
|
||||
|
||||
|
||||
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
|
||||
+2
-2
@@ -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();
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
|
||||
|
||||
QString color2rgba(const QColor& color);
|
||||
|
||||
|
||||
#endif // COMMON_H
|
||||
@@ -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 += \
|
||||
|
||||
Reference in New Issue
Block a user