Wed, 04 Apr 2018 11:41:26 +0300
added a status bar and moved printed messages there
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/basics.h | file | annotate | diff | comparison | revisions | |
src/canvas.cpp | file | annotate | diff | comparison | revisions | |
src/format.h | file | annotate | diff | comparison | revisions | |
src/glcompiler.cpp | file | annotate | diff | comparison | revisions | |
src/hierarchyelement.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.ui | file | annotate | diff | comparison | revisions | |
src/messageLog.cpp | file | annotate | diff | comparison | revisions | |
src/messageLog.h | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Wed Apr 04 11:24:37 2018 +0300 +++ b/CMakeLists.txt Wed Apr 04 11:41:26 2018 +0300 @@ -50,7 +50,6 @@ src/main.cpp src/mainwindow.cpp src/matrixinput.cpp - src/messageLog.cpp src/model.cpp src/partdownloader.cpp src/partdownloadrequest.cpp @@ -120,7 +119,6 @@ src/main.h src/mainwindow.h src/matrixinput.h - src/messageLog.h src/model.h src/partdownloader.h src/partdownloadrequest.h
--- a/src/basics.h Wed Apr 04 11:24:37 2018 +0300 +++ b/src/basics.h Wed Apr 04 11:41:26 2018 +0300 @@ -19,6 +19,7 @@ #pragma once #include <cstdio> #include <cstdlib> +#include <QDate> #include <QFile> #include <QLineF> #include <QMatrix4x4>
--- a/src/canvas.cpp Wed Apr 04 11:24:37 2018 +0300 +++ b/src/canvas.cpp Wed Apr 04 11:41:26 2018 +0300 @@ -59,22 +59,6 @@ QPoint renderPoint {4, height() - 4 - metrics.height() - metrics.descent()}; painter.drawText(renderPoint, format("△ %1", largeNumberRep(m_document.triangleCount()))); } - - // Message log - if (m_window->messageLog()) - { - int y = 0; - int margin = 2; - QColor penColor = textPen().color(); - - for (const MessageManager::Line& line : m_window->messageLog()->getLines()) - { - penColor.setAlphaF(line.alpha); - painter.setPen(penColor); - painter.drawText(QPoint {margin, y + margin + metrics.ascent()}, line.text); - y += metrics.height(); - } - } } /*
--- a/src/format.h Wed Apr 04 11:24:37 2018 +0300 +++ b/src/format.h Wed Apr 04 11:41:26 2018 +0300 @@ -145,3 +145,27 @@ formatHelper (fmtstr, args...); dev.write (fmtstr.toUtf8()); } + +class Printer : public QObject +{ + Q_OBJECT + +public: + void printLine(const QString& line) + { + printf("%s\n", line.toUtf8().constData()); + emit linePrinted(line); + } + +signals: + void linePrinted(const QString& line); +}; + +/* + * Format and print the given args to stdout. Also is reflected to the status bar. + */ +template<typename... Args> +void print(QString formatString, Args&&... args) +{ + singleton<Printer>().printLine(format(formatString, args...)); +}
--- a/src/glcompiler.cpp Wed Apr 04 11:24:37 2018 +0300 +++ b/src/glcompiler.cpp Wed Apr 04 11:41:26 2018 +0300 @@ -61,7 +61,7 @@ } } - element->print("OpenGL ERROR: at %1:%2: %3", file, line, errorMessage); + print("OpenGL ERROR: at %1:%2: %3", file, line, errorMessage); } }
--- a/src/hierarchyelement.h Wed Apr 04 11:24:37 2018 +0300 +++ b/src/hierarchyelement.h Wed Apr 04 11:41:26 2018 +0300 @@ -20,7 +20,6 @@ #include <QObject> #include "main.h" #include "configuration.h" -#include "messageLog.h" #include "mainwindow.h" class GuiUtilities; @@ -48,14 +47,6 @@ // Utility functions QString preferredLicenseText() const; - // Format and print the given args to the message log. - template<typename... Args> - void print(QString formatString, Args... args) - { - formatHelper(formatString, args...); - m_window->addMessage(formatString); - } - protected: MainWindow* m_window; DocumentManager* m_documents;
--- a/src/mainwindow.cpp Wed Apr 04 11:24:37 2018 +0300 +++ b/src/mainwindow.cpp Wed Apr 04 11:41:26 2018 +0300 @@ -27,7 +27,6 @@ #include "canvas.h" #include "mainwindow.h" #include "lddocument.h" -#include "messageLog.h" #include "ui_mainwindow.h" #include "primitives.h" #include "editmodes/abstractEditMode.h" @@ -59,7 +58,15 @@ m_documents (new DocumentManager (this)), m_currentDocument (nullptr) { - m_messageLog = new MessageManager {this}; + connect( + &singleton<Printer>(), + &Printer::linePrinted, + [&](const QString& line) + { + this->statusBar()->showMessage(line, 5000); + } + ); + ui.setupUi (this); this->restoreGeometry(config::mainWindowGeometry()); this->restoreState(config::mainWindowState()); @@ -608,14 +615,6 @@ return false; } -void MainWindow::addMessage(QString message) -{ - messageLog()->addLine(message); - - // Also print it to stdout - fprint(stdout, "%1\n", message); -} - /* * Returns an icon from built-in resources. */ @@ -953,7 +952,7 @@ renderer = new Canvas {document, this}; m_renderers[document] = renderer; ui.rendererStack->addWidget(renderer); - connect(m_messageLog, SIGNAL(changed()), renderer, SLOT(update())); + //connect(m_messageLog, SIGNAL(changed()), renderer, SLOT(update())); } return renderer;
--- a/src/mainwindow.h Wed Apr 04 11:24:37 2018 +0300 +++ b/src/mainwindow.h Wed Apr 04 11:41:26 2018 +0300 @@ -62,7 +62,6 @@ explicit MainWindow(QWidget* parent = nullptr, Qt::WindowFlags flags = 0); ~MainWindow(); - void addMessage (QString msg); void applyToActions(function<void(QAction*)> function); void changeDocument (LDDocument* f); void clearSelection(); @@ -109,13 +108,6 @@ static QPixmap getIcon(QString iconName); - template<typename... Args> - void print(QString formatString, Args... args) - { - formatHelper(formatString, args...); - addMessage(formatString); - } - signals: void gridChanged();
--- a/src/mainwindow.ui Wed Apr 04 11:24:37 2018 +0300 +++ b/src/mainwindow.ui Wed Apr 04 11:41:26 2018 +0300 @@ -47,8 +47,8 @@ <rect> <x>0</x> <y>0</y> - <width>98</width> - <height>28</height> + <width>926</width> + <height>336</height> </rect> </property> <attribute name="label"> @@ -71,7 +71,7 @@ <x>0</x> <y>0</y> <width>926</width> - <height>389</height> + <height>336</height> </rect> </property> <attribute name="label"> @@ -101,8 +101,8 @@ <rect> <x>0</x> <y>0</y> - <width>227</width> - <height>126</height> + <width>926</width> + <height>336</height> </rect> </property> <attribute name="label"> @@ -205,8 +205,8 @@ <rect> <x>0</x> <y>0</y> - <width>98</width> - <height>93</height> + <width>926</width> + <height>336</height> </rect> </property> <attribute name="label"> @@ -239,7 +239,7 @@ <x>0</x> <y>0</y> <width>1010</width> - <height>26</height> + <height>31</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -607,6 +607,7 @@ <addaction name="actionCoverer"/> <addaction name="actionEdger2"/> </widget> + <widget class="QStatusBar" name="statusBar"/> <action name="actionNewPart"> <property name="icon"> <iconset resource="../ldforge.qrc"> @@ -1779,6 +1780,7 @@ </customwidgets> <resources> <include location="../ldforge.qrc"/> + <include location="../ldforge.qrc"/> </resources> <connections/> </ui>
--- a/src/messageLog.cpp Wed Apr 04 11:24:37 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 - 2018 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QTimer> -#include <QDate> -#include "messageLog.h" -#include "glrenderer.h" -#include "mainwindow.h" - -enum -{ - MaxMessages = 5, - ExpireTime = 5000, - FadeTime = 500 -}; - -// ------------------------------------------------------------------------------------------------- -// -MessageManager::MessageManager(QObject* parent) : - QObject {parent} -{ - m_ticker = new QTimer; - m_ticker->start (100); - connect (m_ticker, SIGNAL (timeout()), this, SLOT (tick())); -} - -// ------------------------------------------------------------------------------------------------- -// -MessageManager::Line::Line (QString text) : - text (text), - alpha (1.0f), - expiry (QDateTime::currentDateTime().addMSecs (ExpireTime)) {} - -// ------------------------------------------------------------------------------------------------- -// -bool MessageManager::Line::update (bool& changed) -{ - changed = false; - QDateTime now = QDateTime::currentDateTime(); - int msec = now.msecsTo (expiry); - - if (now >= expiry) - { - // Message line has expired - changed = true; - return false; - } - - if (msec <= FadeTime) - { - // Message line has not expired but is fading out - alpha = ( (float) msec) / FadeTime; - changed = true; - } - - return true; -} - -// ------------------------------------------------------------------------------------------------- -// -// Add a line to the message manager. -// -void MessageManager::addLine (QString line) -{ - // If there's too many entries, pop the excess out - while (countof(m_lines) >= MaxMessages) - m_lines.removeFirst(); - - m_lines.append(Line {line}); - emit changed(); -} - -// ------------------------------------------------------------------------------------------------- -// -// Ticks the message manager. All lines are ticked and the renderer scene is redrawn if something -// changed. -// -void MessageManager::tick() -{ - if (m_lines.isEmpty()) - return; - - bool changed = false; - - for (int i = 0; i < countof(m_lines); ++i) - { - bool lineChanged; - - if (not m_lines[i].update (lineChanged)) - m_lines.removeAt (i--); - - changed |= lineChanged; - } - - if (changed and parent()) - emit this->changed(); -} - -// ============================================================================= -// -const QList<MessageManager::Line>& MessageManager::getLines() const -{ - return m_lines; -}
--- a/src/messageLog.h Wed Apr 04 11:24:37 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 - 2018 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include <QObject> -#include <QDate> -#include "main.h" -#include "basics.h" - -class GLRenderer; -class QTimer; - -// -// The message manager is an object which keeps track of messages that appear -// on the renderer's screen. Each line is contained in a separate object which -// contains the text, expiry time and alpha. The message manager is doubly -// linked to its corresponding renderer. -// -// Message manager calls its tick() function regularly to update the messages, -// where each line's expiry is checked for. Lines begin to fade out when nearing -// their expiry. If the message manager's lines change, the renderer undergoes -// repainting. -// -class MessageManager : public QObject -{ - Q_OBJECT - -public: - // A single line of the message log. - class Line - { - public: - // Constructs a line with the given \c text - Line (QString text); - - // Check this line's expiry and update alpha accordingly. @changed - // is updated to whether the line has somehow changed since the - // last update. - // - // Returns true if the line is to still stick around, false if it - // expired. - bool update (bool& changed); - - QString text; - float alpha; - QDateTime expiry; - }; - - // Constructs the message manager. - explicit MessageManager(QObject* parent = nullptr); - - // Adds a line with the given \c text to the message manager. - void addLine (QString line); - - // Returns all active lines in the message manager. - const QList<Line>& getLines() const; - -signals: - void changed(); - -private: - QList<Line> m_lines; - QTimer* m_ticker; - -private slots: - void tick(); -};