diff --git a/classes/action-handlers/actionfilehandlers.cpp b/classes/action-handlers/actionfilehandlers.cpp index 80d91b4..a7d95f9 100644 --- a/classes/action-handlers/actionfilehandlers.cpp +++ b/classes/action-handlers/actionfilehandlers.cpp @@ -51,9 +51,10 @@ void ActionFileHandlers::newImage_triggered() EditorTabImage *ed = new EditorTabImage(this->mMainWindow->parentWidget()); this->connect(ed, SIGNAL(documentChanged()), SLOT(documentChanged())); + emit this->tabCreated(ed); + name = this->mMainWindow->findAvailableName(name); ed->document()->setDocumentName(name); - emit this->tabCreated(ed, name, ed->document()->documentFilename()); } } //----------------------------------------------------------------------------- @@ -87,9 +88,10 @@ void ActionFileHandlers::newFont_triggered() ed->setFontCharacters(chars, family, style, size, monospaced, antialiasing); + emit this->tabCreated(ed); + name = this->mMainWindow->findAvailableName(name); ed->document()->setDocumentName(name); - emit this->tabCreated(ed, name, ed->document()->documentFilename()); } } } @@ -246,7 +248,7 @@ void ActionFileHandlers::openFile(const QString &filename) EditorTabImage *ed = new EditorTabImage(this->mMainWindow->parentWidget()); this->connect(ed, SIGNAL(documentChanged()), SLOT(documentChanged())); - emit this->tabCreated(ed, "", filename); + emit this->tabCreated(ed); ed->document()->load(filename); } if (isFont) @@ -254,7 +256,7 @@ void ActionFileHandlers::openFile(const QString &filename) EditorTabFont *ed = new EditorTabFont(this->mMainWindow->parentWidget()); this->connect(ed, SIGNAL(documentChanged()), SLOT(documentChanged())); - emit this->tabCreated(ed, "", filename); + emit this->tabCreated(ed); ed->document()->load(filename); } if (isImageBinary) @@ -279,7 +281,7 @@ void ActionFileHandlers::openFile(const QString &filename) } } - emit this->tabCreated(ed, name, filename); + emit this->tabCreated(ed); ed->document()->setDocumentName(name); } } @@ -307,21 +309,12 @@ void ActionFileHandlers::openImage(QImage *image, const QString &documentName) ed->document()->setDocumentName(name); - emit this->tabCreated(ed, name, ""); - - emit this->tabChanged(ed, "* " + name, ""); + emit this->tabCreated(ed); } //----------------------------------------------------------------------------- void ActionFileHandlers::documentChanged() { QWidget *w = qobject_cast(sender()); - IEditor *editor = dynamic_cast (w); - if (editor != NULL) - { - if (editor->document()->changed()) - emit this->tabChanged(w, "* " + editor->document()->documentName(), editor->document()->documentFilename()); - else - emit this->tabChanged(w, editor->document()->documentName(), editor->document()->documentFilename()); - } + emit this->tabChanged(w); } //----------------------------------------------------------------------------- diff --git a/classes/action-handlers/actionfilehandlers.h b/classes/action-handlers/actionfilehandlers.h index 2e3209a..a7c7c6e 100644 --- a/classes/action-handlers/actionfilehandlers.h +++ b/classes/action-handlers/actionfilehandlers.h @@ -36,8 +36,8 @@ public: signals: void rememberFilename(const QString &filename); void closeRequest(QWidget *tab); - void tabChanged(QWidget *w, const QString &documentName, const QString &filename); - void tabCreated(QWidget *w, const QString &documentName, const QString &filename); + void tabChanged(QWidget *w); + void tabCreated(QWidget *w); public slots: void newImage_triggered(); diff --git a/classes/data/fontdocument.cpp b/classes/data/fontdocument.cpp index 57fb091..72e4085 100644 --- a/classes/data/fontdocument.cpp +++ b/classes/data/fontdocument.cpp @@ -43,7 +43,7 @@ FontDocument::FontDocument(QObject *parent) : this->setDocumentName(tr("Font", "new font name")); this->setDocumentFilename(""); this->setOutputFilename(""); - this->setChanged(false); + this->setChanged(true); this->setAntialiasing(false); this->setMonospaced(false); } diff --git a/classes/data/imagedocument.cpp b/classes/data/imagedocument.cpp index d71dcb4..ae8c69a 100644 --- a/classes/data/imagedocument.cpp +++ b/classes/data/imagedocument.cpp @@ -46,7 +46,7 @@ ImageDocument::ImageDocument(QObject *parent) : this->setDocumentName(tr("Image", "new image name")); this->setDocumentFilename(""); this->setOutputFilename(""); - this->setChanged(false); + this->setChanged(true); } //----------------------------------------------------------------------------- ImageDocument::~ImageDocument() diff --git a/controls/main/mainwindow.cpp b/controls/main/mainwindow.cpp index 630bc9f..3373d27 100644 --- a/controls/main/mainwindow.cpp +++ b/controls/main/mainwindow.cpp @@ -203,8 +203,8 @@ void MainWindow::createHandlers() this->connect(this->ui->actionQuit, SIGNAL(triggered()), SLOT(close())); this->connect(this->mFileHandlers, SIGNAL(rememberFilename(QString)), SLOT(rememberFilename(QString))); this->connect(this->mFileHandlers, SIGNAL(closeRequest(QWidget*)), SLOT(closeRequest(QWidget*))); - this->connect(this->mFileHandlers, SIGNAL(tabChanged(QWidget*,QString,QString)), SLOT(tabChanged(QWidget*,QString,QString))); - this->connect(this->mFileHandlers, SIGNAL(tabCreated(QWidget*,QString,QString)), SLOT(tabCreated(QWidget*,QString,QString))); + this->connect(this->mFileHandlers, SIGNAL(tabChanged(QWidget*)), SLOT(tabChanged(QWidget*))); + this->connect(this->mFileHandlers, SIGNAL(tabCreated(QWidget*)), SLOT(tabCreated(QWidget*))); this->mEditHandlers = new ActionEditHandlers(this); this->mEditHandlers->connect(this->ui->actionEditUndo, SIGNAL(triggered()), SLOT(undo_triggered())); @@ -246,6 +246,26 @@ void MainWindow::createHandlers() this->mFileHandlers->connect(this->mFontHandlers, SIGNAL(imageCreated(QImage*,QString)), SLOT(openImage(QImage*,QString))); } //----------------------------------------------------------------------------- +void MainWindow::tabTextUpdate(QWidget *widget) +{ + int index = this->ui->tabWidget->indexOf(widget); + if (index >= 0) + { + IEditor *editor = qobject_cast(widget); + if (editor != NULL) + { + QString name; + if (editor->document()->changed()) + name = "* " + editor->document()->documentName(); + else + name = editor->document()->documentName(); + + this->ui->tabWidget->setTabText(index, name); + this->ui->tabWidget->setTabToolTip(index, editor->document()->documentFilename()); + } + } +} +//----------------------------------------------------------------------------- void MainWindow::on_tabWidget_tabCloseRequested(int index) { QWidget *w = this->ui->tabWidget->widget(index); @@ -461,21 +481,20 @@ QString MainWindow::findAvailableName(const QString &prefix) return result; } //----------------------------------------------------------------------------- -void MainWindow::tabChanged(QWidget *tab, const QString &text, const QString &tooltip) +void MainWindow::tabChanged(QWidget *tab) { int index = this->ui->tabWidget->indexOf(tab); if (index >= 0) { - this->ui->tabWidget->setTabText(index, text); - this->ui->tabWidget->setTabToolTip(index, tooltip); + this->tabTextUpdate(tab); } } //----------------------------------------------------------------------------- -int MainWindow::tabCreated(QWidget *newTab, const QString &name, const QString &tooltip) +int MainWindow::tabCreated(QWidget *newTab) { - int index = this->ui->tabWidget->addTab(newTab, name); + int index = this->ui->tabWidget->addTab(newTab, ""); this->ui->tabWidget->setCurrentIndex(index); - this->ui->tabWidget->setTabToolTip(index, tooltip); + this->tabTextUpdate(newTab); this->connect(newTab, SIGNAL(statusChanged()), SLOT(statusChanged())); diff --git a/controls/main/mainwindow.h b/controls/main/mainwindow.h index 094996b..e4f4659 100644 --- a/controls/main/mainwindow.h +++ b/controls/main/mainwindow.h @@ -59,6 +59,7 @@ private: void selectLocale(const QString &localeName); void checkStartPageVisible(); void createHandlers(); + void tabTextUpdate(QWidget *widget); ActionFileHandlers *mFileHandlers; ActionEditHandlers *mEditHandlers; @@ -78,8 +79,8 @@ private slots: void rememberFilename(const QString &filename); void closeRequest(QWidget *tab); - void tabChanged(QWidget *tab, const QString &text, const QString &tooltip); - int tabCreated(QWidget *newTab, const QString &name, const QString &tooltip); + void tabChanged(QWidget *tab); + int tabCreated(QWidget *newTab); void statusChanged(); public: IEditor *currentEditor();