initial commit
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
#include "cfontview.h"
|
||||
#include "ui_cfontview.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
cFontView::cFontView(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::cFontView)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_lpSampleText->setAutoFillBackground(true);
|
||||
this->setMouseTracking(true);
|
||||
this->setAttribute(Qt::WA_Hover);
|
||||
|
||||
QPalette palette = this->palette();
|
||||
m_defaultColor = palette.color(this->backgroundRole());
|
||||
}
|
||||
|
||||
cFontView::~cFontView()
|
||||
@@ -21,5 +29,45 @@ void cFontView::setText(const QString& text)
|
||||
|
||||
void cFontView::setFont(const QFont& font)
|
||||
{
|
||||
ui->m_lpFontName->setText(font.family());
|
||||
ui->m_lpSampleText->setFont(font);
|
||||
}
|
||||
|
||||
void cFontView::setBackground(const QColor& color)
|
||||
{
|
||||
m_backgroundColor = color;
|
||||
setColor();
|
||||
}
|
||||
|
||||
void cFontView::setForeground(const QColor& color)
|
||||
{
|
||||
m_foregroundColor = color;
|
||||
setColor();
|
||||
}
|
||||
|
||||
void cFontView::setColor()
|
||||
{
|
||||
QString foreground;
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if(!foreground.isEmpty() || !background.isEmpty())
|
||||
ui->m_lpSampleText->setStyleSheet("QLabel { " + foreground + background + " }");
|
||||
}
|
||||
|
||||
void cFontView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
+15
-1
@@ -1,7 +1,11 @@
|
||||
#ifndef CFONTVIEW_H
|
||||
#define CFONTVIEW_H
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
#include <QColor>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class cFontView;
|
||||
@@ -13,13 +17,23 @@ class cFontView : public QWidget
|
||||
|
||||
public:
|
||||
explicit cFontView(QWidget *parent = nullptr);
|
||||
~cFontView();
|
||||
~cFontView() override;
|
||||
|
||||
void setText(const QString& text);
|
||||
void setFont(const QFont& font);
|
||||
void setBackground(const QColor& color);
|
||||
void setForeground(const QColor& color);
|
||||
|
||||
private:
|
||||
Ui::cFontView* ui;
|
||||
QColor m_backgroundColor;
|
||||
QColor m_foregroundColor;
|
||||
QColor m_defaultColor;
|
||||
|
||||
void setColor();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
};
|
||||
|
||||
#endif // CFONTVIEW_H
|
||||
|
||||
+45
-10
@@ -13,7 +13,7 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@@ -30,16 +30,51 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="m_lpSampleText">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<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">
|
||||
<property name="text">
|
||||
<string>Lore Ipsum</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="m_lpFontName">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
+99
-10
@@ -3,28 +3,31 @@
|
||||
|
||||
#include "cfontview.h"
|
||||
|
||||
#include <QFontDatabase>
|
||||
#include <QSettings>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
cMainWindow::cMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::cMainWindow)
|
||||
cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::cMainWindow),
|
||||
m_lpSplashScreen(lpSplashScreen)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
initUI();
|
||||
createActions();
|
||||
|
||||
QFontDatabase fontDatabase;
|
||||
m_fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\a song for jennifer.ttf");
|
||||
m_fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\Grunge Handwriting.ttf");
|
||||
|
||||
fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\a song for jennifer.ttf");
|
||||
fontDatabase.addApplicationFont("C:\\Temp\\Fonts\\Grunge Handwriting.ttf");
|
||||
|
||||
QStringList families = fontDatabase.families();
|
||||
QStringList families = m_fontDatabase.families();
|
||||
|
||||
for(const QString& family : families)
|
||||
{
|
||||
cFontView* lpFontView = new cFontView(this);
|
||||
lpFontView->setText(family);
|
||||
lpFontView->setFont(QFont(family, 16));
|
||||
lpFontView->setBackground(Qt::white);
|
||||
lpFontView->setForeground(Qt::black);
|
||||
ui->m_lpLayout->addWidget(lpFontView);
|
||||
}
|
||||
}
|
||||
@@ -33,3 +36,89 @@ cMainWindow::~cMainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void cMainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("main/width", QVariant::fromValue(size().width()));
|
||||
settings.setValue("main/height", QVariant::fromValue(size().height()));
|
||||
settings.setValue("main/x", QVariant::fromValue(x()));
|
||||
settings.setValue("main/y", QVariant::fromValue(y()));
|
||||
if(this->isMaximized())
|
||||
settings.setValue("main/maximized", QVariant::fromValue(true));
|
||||
else
|
||||
settings.setValue("main/maximized", QVariant::fromValue(false));
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void cMainWindow::initUI()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
if(!settings.value("main/maximized").toBool())
|
||||
{
|
||||
qint32 iX = settings.value("main/x", QVariant::fromValue(-1)).toInt();
|
||||
qint32 iY = settings.value("main/y", QVariant::fromValue(-1)).toInt();
|
||||
qint32 iWidth = settings.value("main/width", QVariant::fromValue(-1)).toInt();
|
||||
qint32 iHeight = settings.value("main/height", QVariant::fromValue(-1)).toInt();
|
||||
|
||||
if(iWidth != -1 && iHeight != -1)
|
||||
resize(iWidth, iHeight);
|
||||
if(iX != -1 && iY != -1)
|
||||
move(iX, iY);
|
||||
}
|
||||
|
||||
// m_lpProgressBar = new QProgressBar(this);
|
||||
// m_lpProgressBar->setVisible(false);
|
||||
// ui->m_lpStatusBar->addPermanentWidget(m_lpProgressBar);
|
||||
}
|
||||
|
||||
void cMainWindow::createActions()
|
||||
{
|
||||
setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
|
||||
createFileActions();
|
||||
createContextActions();
|
||||
|
||||
// connect(ui->m_lpFileList, &cTreeView::deleteEntrys, this, &cMainWindow::onDeleteEntrys);
|
||||
// connect(ui->m_lpThumbnailSize, &QSlider::valueChanged, this, &cMainWindow::onThumbnailSize);
|
||||
}
|
||||
|
||||
void cMainWindow::createContextActions()
|
||||
{
|
||||
}
|
||||
|
||||
void cMainWindow::createFileActions()
|
||||
{
|
||||
// m_lpFileToolBar = addToolBar("file");
|
||||
|
||||
// const QIcon openIcon = QIcon::fromTheme("document-open");
|
||||
// m_lpOpenFileAction = m_lpFileToolBar->addAction(openIcon, tr("&Open..."), this, &cMainWindow::onAddFile);
|
||||
// m_lpOpenFileAction->setShortcut(QKeySequence::Open);
|
||||
|
||||
// const QIcon openDirectoryIcon = QIcon::fromTheme("folder");
|
||||
// m_lpOpenDirectoryAction = m_lpFileToolBar->addAction(openIcon, tr("&Open Folder..."), this, &cMainWindow::onAddFolder);
|
||||
|
||||
|
||||
// m_lpListToolBar = addToolBar("list");
|
||||
|
||||
// const QIcon deleteIcon = QIcon::fromTheme("edit-delete");
|
||||
// m_lpDeleteAction = m_lpListToolBar->addAction(deleteIcon, tr("&Delete"), this, &cMainWindow::onDeleteEntrys);
|
||||
// m_lpDeleteAction->setShortcut(QKeySequence::Delete);
|
||||
|
||||
// const QIcon clearIcon = QIcon::fromTheme("edit-clear");
|
||||
// m_lpClearAction = m_lpListToolBar->addAction(clearIcon, tr("&Clear"), this, &cMainWindow::onClearList);
|
||||
|
||||
|
||||
// m_lpActionToolBar = addToolBar("action");
|
||||
|
||||
// const QIcon convertIcon = QIcon::fromTheme("system-run");
|
||||
// m_lpConvertAction = m_lpActionToolBar->addAction(convertIcon, tr("&Convert"), this, &cMainWindow::onConvert);
|
||||
// m_lpConvertAction->setShortcut(QKeySequence::Delete);
|
||||
|
||||
// const QIcon stopIcon = QIcon::fromTheme("process-stop");
|
||||
// m_lpStopAction = m_lpActionToolBar->addAction(stopIcon, tr("&Stop"), this, &cMainWindow::onStop);
|
||||
}
|
||||
|
||||
+18
-2
@@ -1,7 +1,13 @@
|
||||
#ifndef CMAINWINDOW_H
|
||||
#define CMAINWINDOW_H
|
||||
|
||||
|
||||
#include "csplashscreen.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFontDatabase>
|
||||
#include <QCloseEvent>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class cMainWindow; }
|
||||
@@ -12,10 +18,20 @@ class cMainWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
cMainWindow(QWidget *parent = nullptr);
|
||||
cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent = nullptr);
|
||||
~cMainWindow();
|
||||
|
||||
private:
|
||||
Ui::cMainWindow *ui;
|
||||
Ui::cMainWindow* ui;
|
||||
cSplashScreen* m_lpSplashScreen;
|
||||
QFontDatabase m_fontDatabase;
|
||||
|
||||
void initUI();
|
||||
void createActions();
|
||||
void createFileActions();
|
||||
void createContextActions();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
};
|
||||
#endif // CMAINWINDOW_H
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>cMainWindow</string>
|
||||
<string/>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*!
|
||||
\file csplashscreen.cpp
|
||||
|
||||
*/
|
||||
|
||||
#include "csplashscreen.h"
|
||||
|
||||
#include <QStyleOptionProgressBar>
|
||||
|
||||
|
||||
cSplashScreen::cSplashScreen(const QPixmap& pixmap, QFont& font) :
|
||||
QSplashScreen(pixmap),
|
||||
m_iMax(100),
|
||||
m_iProgress(0)
|
||||
{
|
||||
setFont(font);
|
||||
m_textDocument.setDefaultFont(font);
|
||||
}
|
||||
|
||||
void cSplashScreen::setMax(qint32 max)
|
||||
{
|
||||
m_iMax = max;
|
||||
}
|
||||
|
||||
void cSplashScreen::drawContents(QPainter *painter)
|
||||
{
|
||||
painter->translate(m_rect.topLeft());
|
||||
m_textDocument.setHtml(m_szMessage);
|
||||
m_textDocument.drawContents(painter);
|
||||
|
||||
QStyleOptionProgressBar pbstyle;
|
||||
pbstyle.initFrom(this);
|
||||
pbstyle.state = QStyle::State_Enabled;
|
||||
pbstyle.textVisible = false;
|
||||
pbstyle.minimum = 0;
|
||||
pbstyle.maximum = m_iMax;
|
||||
pbstyle.progress = m_iProgress;
|
||||
pbstyle.invertedAppearance = false;
|
||||
pbstyle.rect = QRect(0, 330, 390, 10); // Where is it.
|
||||
|
||||
// Draw it...
|
||||
style()->drawControl(QStyle::CE_ProgressBar, &pbstyle, painter, this);
|
||||
}
|
||||
|
||||
void cSplashScreen::showStatusMessage(const QString& message)
|
||||
{
|
||||
m_szMessage = message;
|
||||
showMessage(m_szMessage);
|
||||
}
|
||||
|
||||
void cSplashScreen::addStatusMessage(const QString& message)
|
||||
{
|
||||
m_szMessage.append(message);
|
||||
showMessage(m_szMessage);
|
||||
}
|
||||
|
||||
void cSplashScreen::setMessageRect(QRect rect)
|
||||
{
|
||||
m_rect = rect;
|
||||
m_textDocument.setTextWidth(rect.width());
|
||||
}
|
||||
|
||||
void cSplashScreen::setProgress(int value)
|
||||
{
|
||||
m_iProgress = value;
|
||||
update();
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*!
|
||||
\file csplashscreen.h
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CSPLASHSCREEN_H
|
||||
#define CSPLASHSCREEN_H
|
||||
|
||||
|
||||
#include <QSplashScreen>
|
||||
#include <QPainter>
|
||||
#include <QTextDocument>
|
||||
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\class cSplashScreen csplashscreen.h "csplashscreen.h"
|
||||
*/
|
||||
class cSplashScreen : public QSplashScreen
|
||||
{
|
||||
public:
|
||||
cSplashScreen(const QPixmap& pixmap, QFont &font);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn drawContents
|
||||
\param painter
|
||||
*/
|
||||
virtual void drawContents(QPainter *painter);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn showStatusMessage
|
||||
\param message
|
||||
*/
|
||||
void showStatusMessage(const QString &message);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn addStatusMessage
|
||||
\param message
|
||||
*/
|
||||
void addStatusMessage(const QString &message);
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn setMessageRect
|
||||
\param rect
|
||||
*/
|
||||
void setMessageRect(QRect rect);
|
||||
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn setMax
|
||||
\param max
|
||||
*/
|
||||
void setMax(qint32 max);
|
||||
|
||||
private:
|
||||
QTextDocument m_textDocument; /*!< TODO: describe */
|
||||
QString m_szMessage; /*!< TODO: describe */
|
||||
QRect m_rect; /*!< TODO: describe */
|
||||
qint32 m_iMax; /*!< TODO: describe */
|
||||
qint32 m_iProgress; /*!< TODO: describe */
|
||||
public slots:
|
||||
/*!
|
||||
\brief
|
||||
|
||||
\fn setProgress
|
||||
\param value
|
||||
*/
|
||||
void setProgress(int value);
|
||||
};
|
||||
|
||||
#endif // CSPLASHSCREEN_H
|
||||
+16
-1
@@ -1,3 +1,9 @@
|
||||
VERSION = 0.0.1.0
|
||||
QMAKE_TARGET_COMPANY = WIN-DESIGN
|
||||
QMAKE_TARGET_PRODUCT = fontManager
|
||||
QMAKE_TARGET_DESCRIPTION = fontManager
|
||||
QMAKE_TARGET_COPYRIGHT = (c) 2019 WIN-DESIGN
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
@@ -9,6 +15,7 @@ CONFIG += c++11
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
|
||||
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
@@ -17,12 +24,14 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
SOURCES += \
|
||||
cfontview.cpp \
|
||||
csplashscreen.cpp \
|
||||
main.cpp \
|
||||
cmainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
cfontview.h \
|
||||
cmainwindow.h
|
||||
cmainwindow.h \
|
||||
csplashscreen.h
|
||||
|
||||
FORMS += \
|
||||
cfontview.ui \
|
||||
@@ -32,3 +41,9 @@ FORMS += \
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
DISTFILES += \
|
||||
images/splash.png
|
||||
|
||||
RESOURCES += \
|
||||
fontmanager.qrc
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/splash.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -1,12 +1,41 @@
|
||||
#include "cmainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
#include "csplashscreen.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
cMainWindow w;
|
||||
w.show();
|
||||
|
||||
a.setApplicationVersion(APP_VERSION);
|
||||
a.setApplicationDisplayName("fontManager");
|
||||
a.setOrganizationName("WIN-DESIGN");
|
||||
a.setOrganizationDomain("windesign.at");
|
||||
a.setApplicationName("fontManager");
|
||||
|
||||
QSettings settings;
|
||||
|
||||
QPixmap pixmap(":/images/splash.png");
|
||||
QFont splashFont;
|
||||
cSplashScreen* lpSplash = new cSplashScreen(pixmap, splashFont);
|
||||
|
||||
lpSplash->show();
|
||||
a.processEvents();
|
||||
|
||||
lpSplash->showStatusMessage(QObject::tr("<center>initializing...</denter>"));
|
||||
|
||||
cMainWindow w(lpSplash);
|
||||
|
||||
if(settings.value("main/maximized").toBool())
|
||||
w.showMaximized();
|
||||
else
|
||||
w.show();
|
||||
|
||||
lpSplash->finish(&w);
|
||||
delete lpSplash;
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user