diff --git a/cfontview.cpp b/cfontview.cpp index f60a850..4866e2d 100644 --- a/cfontview.cpp +++ b/cfontview.cpp @@ -1,12 +1,20 @@ #include "cfontview.h" #include "ui_cfontview.h" +#include + 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(); +} diff --git a/cfontview.h b/cfontview.h index 7530c95..6e5041e 100644 --- a/cfontview.h +++ b/cfontview.h @@ -1,7 +1,11 @@ #ifndef CFONTVIEW_H #define CFONTVIEW_H + #include +#include +#include + 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 diff --git a/cfontview.ui b/cfontview.ui index 4e5b766..60a6ac5 100644 --- a/cfontview.ui +++ b/cfontview.ui @@ -13,7 +13,7 @@ Form - + 0 @@ -30,16 +30,51 @@ 0 - - - QFrame::Box - - - QFrame::Plain - - - TextLabel + + + + + + 0 + + + 2 + + + 0 + + + 2 + + + 0 + + + + + 9 + + + 0 + + + + + Lore Ipsum + + + + + + + + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp index fbb808c..2bad0ff 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -3,28 +3,31 @@ #include "cfontview.h" -#include +#include + #include -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); +} diff --git a/cmainwindow.h b/cmainwindow.h index 65f0642..453e058 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -1,7 +1,13 @@ #ifndef CMAINWINDOW_H #define CMAINWINDOW_H + +#include "csplashscreen.h" + #include +#include +#include + 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 diff --git a/cmainwindow.ui b/cmainwindow.ui index f893c2e..2c121ff 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -11,7 +11,7 @@ - cMainWindow + diff --git a/csplashscreen.cpp b/csplashscreen.cpp new file mode 100644 index 0000000..e3883d2 --- /dev/null +++ b/csplashscreen.cpp @@ -0,0 +1,67 @@ +/*! + \file csplashscreen.cpp + +*/ + +#include "csplashscreen.h" + +#include + + +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(); +} diff --git a/csplashscreen.h b/csplashscreen.h new file mode 100644 index 0000000..0ebe29b --- /dev/null +++ b/csplashscreen.h @@ -0,0 +1,78 @@ +/*! + \file csplashscreen.h + +*/ + +#ifndef CSPLASHSCREEN_H +#define CSPLASHSCREEN_H + + +#include +#include +#include + + +/*! + \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 diff --git a/fontManager.pro b/fontManager.pro index 1122c78..887832f 100644 --- a/fontManager.pro +++ b/fontManager.pro @@ -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 diff --git a/fontmanager.qrc b/fontmanager.qrc new file mode 100644 index 0000000..00d0cc6 --- /dev/null +++ b/fontmanager.qrc @@ -0,0 +1,5 @@ + + + images/splash.png + + diff --git a/images/splash.png b/images/splash.png new file mode 100644 index 0000000..5329d63 Binary files /dev/null and b/images/splash.png differ diff --git a/main.cpp b/main.cpp index 705e3e9..7d95057 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,41 @@ #include "cmainwindow.h" #include +#include + +#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("
initializing...")); + + cMainWindow w(lpSplash); + + if(settings.value("main/maximized").toBool()) + w.showMaximized(); + else + w.show(); + + lpSplash->finish(&w); + delete lpSplash; + return a.exec(); }