From cae2627af345f4b4be32a5e187be122caeb28bc0 Mon Sep 17 00:00:00 2001 From: Kandrashin Denis Date: Sun, 2 Dec 2012 23:55:25 +0400 Subject: Show text modification [*] in window title --- source/fb2app.cpp | 16 ---------------- source/fb2dock.cpp | 9 +++++++++ source/fb2dock.hpp | 2 ++ source/fb2head.hpp | 1 + source/fb2main.cpp | 12 ++++-------- source/fb2main.hpp | 3 +-- source/fb2text.cpp | 6 ++++++ source/fb2text.hpp | 4 ++++ 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/source/fb2app.cpp b/source/fb2app.cpp index 010a3ab..0756f6d 100644 --- a/source/fb2app.cpp +++ b/source/fb2app.cpp @@ -23,22 +23,6 @@ QString FbApplication::lastCommit() void FbApplication::handleMessage(QtMsgType type, const char *msg) { - /* - switch (type) { - case QtDebugMsg: - fprintf(stderr, "Debug: %s\n", msg); - break; - case QtWarningMsg: - fprintf(stderr, "Warning: %s\n", msg); - break; - case QtCriticalMsg: - fprintf(stderr, "Critical: %s\n", msg); - break; - case QtFatalMsg: - fprintf(stderr, "Fatal: %s\n", msg); - abort(); - } - */ emit logMessage(type, QString::fromUtf8(msg)); } diff --git a/source/fb2dock.cpp b/source/fb2dock.cpp index 4cec1d3..0b91598 100644 --- a/source/fb2dock.cpp +++ b/source/fb2dock.cpp @@ -60,6 +60,9 @@ FbMainDock::FbMainDock(QWidget *parent) connect(m_text->page(), SIGNAL(error(int,int,QString)), SLOT(error(int,int))); connect(m_text->page(), SIGNAL(fatal(int,int,QString)), SLOT(error(int,int))); connect(m_text->page(), SIGNAL(status(QString)), parent, SLOT(status(QString))); + connect(m_text, SIGNAL(modificationChanged(bool)), SLOT(textChanged(bool))); + connect(m_head, SIGNAL(modificationChanged(bool)), SLOT(textChanged(bool))); + connect(m_code, SIGNAL(modificationChanged(bool)), SLOT(textChanged(bool))); connect(m_head, SIGNAL(status(QString)), parent, SLOT(status(QString))); connect(m_code, SIGNAL(status(QString)), parent, SLOT(status(QString))); connect(this, SIGNAL(status(QString)), parent, SLOT(status(QString))); @@ -68,6 +71,7 @@ FbMainDock::FbMainDock(QWidget *parent) void FbMainDock::switchMode(Fb::Mode mode) { if (mode == m_mode) return; + isSwitched = isModified(); if (currentWidget() == m_code) { QString xml = m_code->toPlainText(); switch (m_mode) { @@ -188,6 +192,11 @@ bool FbMainDock::save(QIODevice *device, const QString &codec) return true; } +void FbMainDock::textChanged(bool changed) +{ + emit modificationChanged(isSwitched || changed); +} + bool FbMainDock::isModified() const { if (isSwitched) return true; diff --git a/source/fb2dock.hpp b/source/fb2dock.hpp index 735421b..b4588cc 100644 --- a/source/fb2dock.hpp +++ b/source/fb2dock.hpp @@ -34,9 +34,11 @@ public: bool isModified() const; signals: + void modificationChanged(bool changed); void status(const QString &text); private slots: + void textChanged(bool changed); void error(int row, int col); private: diff --git a/source/fb2head.hpp b/source/fb2head.hpp index 258173f..d8fd7e2 100644 --- a/source/fb2head.hpp +++ b/source/fb2head.hpp @@ -182,6 +182,7 @@ public: void disconnectActions(); signals: + void modificationChanged(bool changed); void status(const QString &text); public slots: diff --git a/source/fb2main.cpp b/source/fb2main.cpp index a55aad1..bcb4958 100644 --- a/source/fb2main.cpp +++ b/source/fb2main.cpp @@ -27,13 +27,14 @@ FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode) , isSwitched(false) , isUntitled(true) { - connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString))); + connect(qApp, SIGNAL(logMessage(QtMsgType, QString)), SLOT(logMessage(QtMsgType, QString))); setUnifiedTitleAndToolBarOnMac(true); setAttribute(Qt::WA_DeleteOnClose); setWindowIcon(QIcon(":icon.ico")); mainDock = new FbMainDock(this); + connect(mainDock, SIGNAL(modificationChanged(bool)), SLOT(textChanged(bool))); setCentralWidget(mainDock); createActions(); @@ -143,12 +144,7 @@ void FbMainWindow::about() QMessageBox::about(this, tr("About fb2edit"), text); } -void FbMainWindow::documentWasModified() -{ -// setModified(isSwitched || codeEdit->isModified()); -} - -void FbMainWindow::setModified(bool modified) +void FbMainWindow::textChanged(bool modified) { QFileInfo info = windowFilePath(); QString title = info.fileName(); @@ -575,7 +571,7 @@ void FbMainWindow::setCurrentFile(const QString &filename) curFile = info.canonicalFilePath(); } setWindowFilePath(curFile); - setModified(false); + textChanged(false); } QString FbMainWindow::appTitle() const diff --git a/source/fb2main.hpp b/source/fb2main.hpp index 49b62d5..56bf01d 100644 --- a/source/fb2main.hpp +++ b/source/fb2main.hpp @@ -50,7 +50,7 @@ private slots: bool fileSaveAs(); void about(); - void documentWasModified(); + void textChanged(bool modified); void logDestroyed(); void openSettings(); @@ -66,7 +66,6 @@ private: void createStatusBar(); void readSettings(); void writeSettings(); - void setModified(bool modified); bool maybeSave(); bool saveFile(const QString &fileName, const QString &codec = QString()); void setCurrentFile(const QString &fileName = QString()); diff --git a/source/fb2text.cpp b/source/fb2text.cpp index b36f386..912fc81 100644 --- a/source/fb2text.cpp +++ b/source/fb2text.cpp @@ -221,6 +221,7 @@ FbTextEdit::FbTextEdit(QWidget *parent, QObject *owner) setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint))); connect(p, SIGNAL(linkHovered(QString,QString,QString)), SLOT(linkHovered(QString,QString,QString))); + connect(p->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool))); setPage(p); } @@ -461,6 +462,11 @@ void FbTextEdit::mouseMoveEvent(QMouseEvent *event) QWebView::mouseMoveEvent(event); } +void FbTextEdit::cleanChanged(bool clean) +{ + emit modificationChanged(!clean); +} + void FbTextEdit::contextMenu(const QPoint &pos) { QMenu menu, *submenu; diff --git a/source/fb2text.hpp b/source/fb2text.hpp index 00310db..86293b7 100644 --- a/source/fb2text.hpp +++ b/source/fb2text.hpp @@ -97,6 +97,9 @@ public: QWebElement body(); QWebElement doc(); +signals: + void modificationChanged(bool changed); + protected: virtual void mouseMoveEvent(QMouseEvent *event); @@ -113,6 +116,7 @@ public slots: private slots: void linkHovered(const QString &link, const QString &title, const QString &textContent); void contextMenu(const QPoint &pos); + void cleanChanged(bool clean); void treeDestroyed(); void imgsDestroyed(); void noteDestroyed(); -- cgit v1.2.3