From e4311552a1a4629013f239b405a53e0e8a115257 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Wed, 9 Aug 2023 17:31:00 +0200 Subject: [PATCH] initial commit --- ccheckbox.h | 4 +- cfont.cpp | 6 +++ cfont.h | 16 +++++++ cfontview.cpp | 46 +++++++++++++++++++- cfontview.h | 19 ++++++++ clabel.h | 4 +- cmainwindow.cpp | 94 +++++++++++++++++++++++++++++++--------- cmainwindow.h | 18 +++++++- cmainwindow.ui | 18 +++++--- csplashscreen.cpp | 22 +++++----- csplashscreen.h | 10 ++--- fontManager.pro | 5 +++ fontmanager.qrc | 3 ++ images/tango/index.theme | 14 ++++++ 14 files changed, 232 insertions(+), 47 deletions(-) create mode 100644 cfont.cpp create mode 100644 cfont.h create mode 100644 images/tango/index.theme diff --git a/ccheckbox.h b/ccheckbox.h index 83e1bb4..d2e1e23 100644 --- a/ccheckbox.h +++ b/ccheckbox.h @@ -15,8 +15,8 @@ public: cCheckBox(QWidget *parent = nullptr); protected: - void enterEvent(QEvent *ev) override; - void leaveEvent(QEvent *ev) override; + void enterEvent(QEvent *ev); + void leaveEvent(QEvent *ev); signals: void windowEntered(); diff --git a/cfont.cpp b/cfont.cpp new file mode 100644 index 0000000..cb6a444 --- /dev/null +++ b/cfont.cpp @@ -0,0 +1,6 @@ +#include "cfont.h" + +cFont::cFont(QObject *parent) : QObject(parent) +{ + +} diff --git a/cfont.h b/cfont.h new file mode 100644 index 0000000..1f657c6 --- /dev/null +++ b/cfont.h @@ -0,0 +1,16 @@ +#ifndef CFONT_H +#define CFONT_H + +#include + +class cFont : public QObject +{ + Q_OBJECT +public: + explicit cFont(QObject *parent = nullptr); + +signals: + +}; + +#endif // CFONT_H diff --git a/cfontview.cpp b/cfontview.cpp index 7abcc24..441d1e4 100644 --- a/cfontview.cpp +++ b/cfontview.cpp @@ -39,7 +39,33 @@ void cFontView::setText(const QString& text) void cFontView::setFont(const QFont& font) { - ui->m_lpFontName->setText(font.family()); +// qDebug() << "family: " << font.family(); +// qDebug() << "capitalization: " << font.capitalization(); +// qDebug() << "defaultFamily: " << font.defaultFamily(); +// qDebug() << "families: " << font.families(); +// qDebug() << "family: " << font.family(); +// qDebug() << "fixedPitch: " << font.fixedPitch(); +// qDebug() << "hintingPreference: " << font.hintingPreference(); +// qDebug() << "italic: " << font.italic(); +// qDebug() << "kerning: " << font.kerning(); +// qDebug() << "key: " << font.key(); +// qDebug() << "letterSpacing: " << font.letterSpacing(); +// qDebug() << "letterSpacingType: " << font.letterSpacingType(); +// qDebug() << "overline: " << font.overline(); +// qDebug() << "stretch: " << font.stretch(); +// qDebug() << "strikeOut: " << font.strikeOut(); +// qDebug() << "style: " << font.style(); +// qDebug() << "styleHint: " << font.styleHint(); +// qDebug() << "styleName: " << font.styleName(); +// qDebug() << "styleStrategy: " << font.styleStrategy(); +// qDebug() << "toString: " << font.toString(); +// qDebug() << "underline: " << font.underline(); +// qDebug() << "weight: " << font.weight(); +// qDebug() << "wordSpacing: " << font.wordSpacing(); +// qDebug() << "substitutions: " << font.substitutions(); +// qDebug() << "--------------------"; + + ui->m_lpFontName->setText(font.family() + "(" + font.styleName() + ")"); ui->m_lpSampleText->setFont(font); } @@ -89,3 +115,21 @@ void cFontView::windowLeft() { ui->m_lpFontName->setStyleSheet("QCheckBox { background-color: " + color2rgba(m_defaultColor) + "; }"); } + +cFontViewList::cFontViewList(QObject* parent) : + QObject(parent) +{ +} + +void cFontViewList::add(cFontView* fontView) +{ + this->append(fontView); +} + +void cFontViewList::clearAll() +{ + for(int i = 0;i < count();i++) + delete at(i); + + clear(); +} diff --git a/cfontview.h b/cfontview.h index 7f74143..a804551 100644 --- a/cfontview.h +++ b/cfontview.h @@ -6,6 +6,8 @@ #include #include +#include + namespace Ui { class cFontView; @@ -42,4 +44,21 @@ public slots: void windowLeft(); }; +Q_DECLARE_METATYPE(cFontView*) + +class cFontViewList : public QObject, public QList +{ + Q_OBJECT + +public: + explicit cFontViewList(QObject* parent = nullptr); + + void add(cFontView* fontView); + void clearAll(); + +signals: + +public slots: +}; + #endif // CFONTVIEW_H diff --git a/clabel.h b/clabel.h index 4636f22..50271fa 100644 --- a/clabel.h +++ b/clabel.h @@ -15,8 +15,8 @@ public: cLabel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); protected: - void enterEvent(QEvent *ev) override; - void leaveEvent(QEvent *ev) override; + void enterEvent(QEvent *ev); + void leaveEvent(QEvent *ev); signals: void windowEntered(); diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 083be1d..9e06728 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -1,9 +1,8 @@ #include "cmainwindow.h" #include "ui_cmainwindow.h" -#include "cfontview.h" - #include +#include #include @@ -11,25 +10,17 @@ cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), - m_lpSplashScreen(lpSplashScreen) + m_splashScreen(lpSplashScreen), + m_progressBar(nullptr), + m_fileMenu(nullptr), + m_fileToolBar(nullptr), + m_fileNewAction(nullptr) + { initUI(); createActions(); -// 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(); - - 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); - } + loadSystemFonts(m_splashScreen); } cMainWindow::~cMainWindow() @@ -71,9 +62,15 @@ void cMainWindow::initUI() move(iX, iY); } -// m_lpProgressBar = new QProgressBar(this); -// m_lpProgressBar->setVisible(false); -// ui->m_lpStatusBar->addPermanentWidget(m_lpProgressBar); + m_progressBar = new QProgressBar(this); + m_progressBar->setVisible(false); + ui->m_statusBar->addPermanentWidget(m_progressBar); + + QIcon::setThemeName("TangoMFK"); + qDebug() << QIcon::themeName(); + qDebug() << QIcon::themeSearchPaths(); + qDebug() << QIcon::hasThemeIcon("document-open"); + qDebug() << "done"; } void cMainWindow::createActions() @@ -93,6 +90,17 @@ void cMainWindow::createContextActions() void cMainWindow::createFileActions() { + m_fileMenu = menuBar()->addMenu(tr("&File")); + m_fileToolBar = addToolBar(tr("File Actions")); + + const QIcon newIcon = QIcon::fromTheme("document-new"); + m_fileNewAction = m_fileMenu->addAction(newIcon, tr("&New"), this, &cMainWindow::onFileNew); + m_fileToolBar->addAction(m_fileNewAction); + m_fileNewAction->setPriority(QAction::LowPriority); + m_fileNewAction->setShortcut(QKeySequence::New); + + ui->m_mainToolBar->addAction(m_fileNewAction); + // m_lpFileToolBar = addToolBar("file"); // const QIcon openIcon = QIcon::fromTheme("document-open"); @@ -122,3 +130,49 @@ void cMainWindow::createFileActions() // const QIcon stopIcon = QIcon::fromTheme("process-stop"); // m_lpStopAction = m_lpActionToolBar->addAction(stopIcon, tr("&Stop"), this, &cMainWindow::onStop); } + +void cMainWindow::loadSystemFonts(cSplashScreen* splashScreen) +{ + m_fontViewList.clearAll(); + + QStringList families = m_fontDatabase.families(); + int cnt = 0; + + if(splashScreen) + splashScreen->setMax(families.count()); + else + m_progressBar->setMaximum(families.count()); + + for(const QString& family : families) + { + if(splashScreen) + { + splashScreen->setProgress(cnt); + splashScreen->showStatusMessage("loading " + family + " ..."); + } + else + { + m_progressBar->setValue(cnt); + ui->m_statusBar->showMessage("loading " + family + " ..."); + } + + cFontView* lpFontView = new cFontView(this); + lpFontView->setText("The quick brown fox jumps over the lazy dog"); + lpFontView->setFont(QFont(family, 16)); + lpFontView->setBackground(Qt::white); + lpFontView->setForeground(Qt::black); + ui->m_fontListLayout->addWidget(lpFontView); + + m_fontViewList.add(lpFontView); + + cnt++; + } + + if(!splashScreen) + ui->m_statusBar->showMessage("done.", 2000); +} + +void cMainWindow::onFileNew() +{ + loadSystemFonts(); +} diff --git a/cmainwindow.h b/cmainwindow.h index 453e058..77d2a92 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -4,9 +4,12 @@ #include "csplashscreen.h" +#include "cfontview.h" + #include #include #include +#include QT_BEGIN_NAMESPACE @@ -23,15 +26,28 @@ public: private: Ui::cMainWindow* ui; - cSplashScreen* m_lpSplashScreen; + cSplashScreen* m_splashScreen; + QProgressBar* m_progressBar; QFontDatabase m_fontDatabase; + QMenu* m_fileMenu; + QToolBar* m_fileToolBar; + QAction* m_fileNewAction; + + cFontViewList m_fontViewList; + void initUI(); void createActions(); void createFileActions(); void createContextActions(); + void loadSystemFonts(cSplashScreen* splashScreen = nullptr); + protected: void closeEvent(QCloseEvent* event); + +private slots: + void onFileNew(); + }; #endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui index 2c121ff..77064d4 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -16,7 +16,7 @@ - + true @@ -26,12 +26,12 @@ 0 0 780 - 539 + 527 - + 1 @@ -56,7 +56,7 @@ - + 0 @@ -66,7 +66,15 @@ - + + + TopToolBarArea + + + false + + + diff --git a/csplashscreen.cpp b/csplashscreen.cpp index e3883d2..d008d8e 100644 --- a/csplashscreen.cpp +++ b/csplashscreen.cpp @@ -10,8 +10,8 @@ cSplashScreen::cSplashScreen(const QPixmap& pixmap, QFont& font) : QSplashScreen(pixmap), - m_iMax(100), - m_iProgress(0) + m_max(100), + m_progress(0) { setFont(font); m_textDocument.setDefaultFont(font); @@ -19,13 +19,13 @@ cSplashScreen::cSplashScreen(const QPixmap& pixmap, QFont& font) : void cSplashScreen::setMax(qint32 max) { - m_iMax = max; + m_max = max; } void cSplashScreen::drawContents(QPainter *painter) { painter->translate(m_rect.topLeft()); - m_textDocument.setHtml(m_szMessage); + m_textDocument.setHtml(m_message); m_textDocument.drawContents(painter); QStyleOptionProgressBar pbstyle; @@ -33,8 +33,8 @@ void cSplashScreen::drawContents(QPainter *painter) pbstyle.state = QStyle::State_Enabled; pbstyle.textVisible = false; pbstyle.minimum = 0; - pbstyle.maximum = m_iMax; - pbstyle.progress = m_iProgress; + pbstyle.maximum = m_max; + pbstyle.progress = m_progress; pbstyle.invertedAppearance = false; pbstyle.rect = QRect(0, 330, 390, 10); // Where is it. @@ -44,14 +44,14 @@ void cSplashScreen::drawContents(QPainter *painter) void cSplashScreen::showStatusMessage(const QString& message) { - m_szMessage = message; - showMessage(m_szMessage); + m_message = message; + showMessage(m_message); } void cSplashScreen::addStatusMessage(const QString& message) { - m_szMessage.append(message); - showMessage(m_szMessage); + m_message.append(message); + showMessage(m_message); } void cSplashScreen::setMessageRect(QRect rect) @@ -62,6 +62,6 @@ void cSplashScreen::setMessageRect(QRect rect) void cSplashScreen::setProgress(int value) { - m_iProgress = value; + m_progress = value; update(); } diff --git a/csplashscreen.h b/csplashscreen.h index 0ebe29b..6791952 100644 --- a/csplashscreen.h +++ b/csplashscreen.h @@ -60,11 +60,11 @@ public: 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 */ + QTextDocument m_textDocument; /*!< TODO: describe */ + QString m_message; /*!< TODO: describe */ + QRect m_rect; /*!< TODO: describe */ + qint32 m_max; /*!< TODO: describe */ + qint32 m_progress; /*!< TODO: describe */ public slots: /*! \brief diff --git a/fontManager.pro b/fontManager.pro index 49327a5..dc66830 100644 --- a/fontManager.pro +++ b/fontManager.pro @@ -17,6 +17,9 @@ CONFIG += c++11 DEFINES += QT_DEPRECATED_WARNINGS DEFINES += APP_VERSION=\\\"$$VERSION\\\" +#LIBS += -LC:\dev\3rdParty\exiv2\lib -lexiv2.dll -LC:\dev\3rdParty\libraw\lib -lraw -lws2_32 +LIBS += -lgdi32 + # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. @@ -24,6 +27,7 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\" SOURCES += \ ccheckbox.cpp \ + cfont.cpp \ cfontview.cpp \ clabel.cpp \ common.cpp \ @@ -33,6 +37,7 @@ SOURCES += \ HEADERS += \ ccheckbox.h \ + cfont.h \ cfontview.h \ clabel.h \ cmainwindow.h \ diff --git a/fontmanager.qrc b/fontmanager.qrc index 00d0cc6..3bc132f 100644 --- a/fontmanager.qrc +++ b/fontmanager.qrc @@ -2,4 +2,7 @@ images/splash.png + + images/tango/index.theme + diff --git a/images/tango/index.theme b/images/tango/index.theme new file mode 100644 index 0000000..45b1be8 --- /dev/null +++ b/images/tango/index.theme @@ -0,0 +1,14 @@ +[Icon Theme] +Name=tango +Comment=Original tango icons +Inherits=default +Directories=16x16,22x22,32x32 + +[16x16] +Size=16 + +[22x22] +Size=22 + +[32x32] +Size=32