# HG changeset patch # User Teemu Piippo # Date 1522831286 -10800 # Node ID bc799b9654183968ee49ca52ee7b03376e471321 # Parent 35811339ea728ec01095448c7adf409d0bcddc8d added a status bar and moved printed messages there diff -r 35811339ea72 -r bc799b965418 CMakeLists.txt --- 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 diff -r 35811339ea72 -r bc799b965418 src/basics.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 #include +#include #include #include #include diff -r 35811339ea72 -r bc799b965418 src/canvas.cpp --- 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(); - } - } } /* diff -r 35811339ea72 -r bc799b965418 src/format.h --- 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 +void print(QString formatString, Args&&... args) +{ + singleton().printLine(format(formatString, args...)); +} diff -r 35811339ea72 -r bc799b965418 src/glcompiler.cpp --- 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); } } diff -r 35811339ea72 -r bc799b965418 src/hierarchyelement.h --- 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 #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 - void print(QString formatString, Args... args) - { - formatHelper(formatString, args...); - m_window->addMessage(formatString); - } - protected: MainWindow* m_window; DocumentManager* m_documents; diff -r 35811339ea72 -r bc799b965418 src/mainwindow.cpp --- 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::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; diff -r 35811339ea72 -r bc799b965418 src/mainwindow.h --- 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 function); void changeDocument (LDDocument* f); void clearSelection(); @@ -109,13 +108,6 @@ static QPixmap getIcon(QString iconName); - template - void print(QString formatString, Args... args) - { - formatHelper(formatString, args...); - addMessage(formatString); - } - signals: void gridChanged(); diff -r 35811339ea72 -r bc799b965418 src/mainwindow.ui --- 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 @@ 0 0 - 98 - 28 + 926 + 336 @@ -71,7 +71,7 @@ 0 0 926 - 389 + 336 @@ -101,8 +101,8 @@ 0 0 - 227 - 126 + 926 + 336 @@ -205,8 +205,8 @@ 0 0 - 98 - 93 + 926 + 336 @@ -239,7 +239,7 @@ 0 0 1010 - 26 + 31 @@ -607,6 +607,7 @@ + @@ -1779,6 +1780,7 @@ + diff -r 35811339ea72 -r bc799b965418 src/messageLog.cpp --- 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 . - */ - -#include -#include -#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::getLines() const -{ - return m_lines; -} diff -r 35811339ea72 -r bc799b965418 src/messageLog.h --- 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 . - */ - -#pragma once -#include -#include -#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& getLines() const; - -signals: - void changed(); - -private: - QList m_lines; - QTimer* m_ticker; - -private slots: - void tick(); -};