diff --git a/mainwindow.cpp b/mainwindow.cpp index a891b4f..287fe26 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -307,7 +307,7 @@ void MainWindow::formatTextColor() if(note->type()!=Note::type_html) return; QTextCharFormat format = note->getSelFormat(); QColor color = format.foreground().color(); - QColorDialog dlg(color); + QColorDialog dlg(color, this); if(dlg.exec()==QDialog::Accepted) { color = dlg.currentColor(); @@ -449,11 +449,12 @@ MainWindow::~MainWindow() //saving notes notes->saveAll(); //saving title of last note - if(notes->current()) settings.setLastNote(notes->current()->fileName()); + if(notes->current()) + settings.setLastNote(notes->current()->fileName()); //saving dialog's params settings.setDialogGeometry(saveGeometry()); settings.setDialogState(saveState()); - //saving scrits + //saving scripts settings.setScripts(); //syncing settings settings.save(); @@ -464,7 +465,8 @@ void MainWindow::currentNoteChanged(int old_index, int new_index) if(old_index!=-1) { Note* note = notes->get(old_index); - if(note->type()==Note::type_html) disconnect(note, SIGNAL(formatChanged(QFont)), 0, 0); //disconnecting old note + //disconnecting old note + if(note->type()==Note::type_html) disconnect(note, SIGNAL(formatChanged(QFont)), 0, 0); } // bool not_empty = !notes->empty(); diff --git a/notelist.cpp b/notelist.cpp index 432820d..ce991e8 100644 --- a/notelist.cpp +++ b/notelist.cpp @@ -69,6 +69,8 @@ NoteList::NoteList(QWidget* parent) connect(&settings, SIGNAL(ShowHiddenChanged()), this, SLOT(scanForNewFiles())); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(scanForNewFiles())); + connect(tabs, SIGNAL(tabBarDoubleClickedOnTab(int)), this, SLOT(changeNoteName(int))); + // Save a parent widget pointer. parentWidget = parent; } @@ -80,14 +82,22 @@ NoteList::~NoteList() void NoteList::initNoteTypes() { - registerType(Note::type_text, QObject::tr("Text Note"), QObject::tr("Simple text Note"), ":/res/note_types/txt.png", ":/res/note_types/16/txt.png", "txt,"); - registerType(Note::type_html, QObject::tr("HTML Note"), QObject::tr("Simple Note with text formating"), ":/res/note_types/html.png", ":/res/note_types/16/html.png", "html,htm"); - registerType(Note::type_picture, QObject::tr("Picture Note"), QObject::tr("Simple text Note"), ":/res/note_types/pic.png", ":/res/note_types/16/pic.png", "png,jpeg,jpg,png,gif", false); + registerType(Note::type_text, QObject::tr("Text Note"), + QObject::tr("Simple text Note"), ":/res/note_types/txt.png", + ":/res/note_types/16/txt.png", "txt,"); + registerType(Note::type_html, QObject::tr("HTML Note"), + QObject::tr("Simple Note with text formating"), ":/res/note_types/html.png", + ":/res/note_types/16/html.png", "html,htm"); + registerType(Note::type_picture, QObject::tr("Picture Note"), QObject::tr("Simple text Note"), + ":/res/note_types/pic.png", ":/res/note_types/16/pic.png", "png,jpeg,jpg,png,gif", + false); #ifdef NOTE_TODO_FORMAT - registerType(Note::type_todo, QObject::tr("TODO Note"), QObject::tr("Simple TODO list"), ":/res/note_types/todo.png", ":/res/note_types/16/todo.png", "ztodo"); + registerType(Note::type_todo, QObject::tr("TODO Note"), QObject::tr("Simple TODO list"), + ":/res/note_types/todo.png", ":/res/note_types/16/todo.png", "ztodo"); #endif #ifdef NOTE_XML_FORMAT - registerType(Note::type_xml, QObject::tr("XML Note"), QObject::tr("XML file"), ":/res/note_types/xml.png", ":/res/note_types/16/xml.png", "xml"); + registerType(Note::type_xml, QObject::tr("XML Note"), QObject::tr("XML file"), + ":/res/note_types/xml.png", ":/res/note_types/16/xml.png", "xml"); #endif } @@ -112,7 +122,13 @@ void NoteList::scanForNewFiles() const QString& filename = flist.at(i).fileName(); bool exists = notes_filenames.contains(filename); if(!exists) add(flist.at(i)); - } + } +} + +void NoteList::changeNoteName(int tabIndex) +{ + Q_UNUSED(tabIndex) + renameCurrentNote(); } Note::Type NoteList::getType(const QFileInfo& fileinfo) const diff --git a/notelist.h b/notelist.h index 39a0046..9d26ae3 100644 --- a/notelist.h +++ b/notelist.h @@ -51,6 +51,7 @@ class NoteList : public QObject void remove(int i); void rename(int index, const QString& title); void move(const QString& path); + public slots: void saveAll(); // @@ -65,6 +66,8 @@ private slots: void tabPositionChanged(); void notesPathChanged(); void scanForNewFiles(); + void changeNoteName(int); + signals: void currentNoteChanged(int old_index, int new_index); diff --git a/ztabbar.h b/ztabbar.h index 610012a..945f778 100644 --- a/ztabbar.h +++ b/ztabbar.h @@ -16,10 +16,8 @@ class ZTabBar : public QTabBar public slots: - protected: - void paintEvent(QPaintEvent *); - + void paintEvent(QPaintEvent *); }; #endif // ZTABBAR_H diff --git a/ztabwidget.cpp b/ztabwidget.cpp index 09569af..b39ea57 100644 --- a/ztabwidget.cpp +++ b/ztabwidget.cpp @@ -1,8 +1,32 @@ +#include #include "ztabwidget.h" #include "ztabbar.h" ZTabWidget::ZTabWidget(QWidget *parent) : QTabWidget(parent) { - setTabBar(new ZTabBar(this)); + tabBar = new ZTabBar(this); + // Control double-click on tab bar through an event filter. + tabBar->installEventFilter(this); + setTabBar(tabBar); +} + +// Method is based on code from class MyTabWidget of project https://gitorious.org/qmpq. +bool ZTabWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonDblClick) { + QMouseEvent * mouseEvent = static_cast(event); + int tabIndex; + tabIndex = tabBar->tabAt(mouseEvent->pos()); + if (tabIndex == -1) + // Chosen no a tab. + emit tabBarDoubleClickedOnEmptySpace(); + else + // Chosen a tab + emit tabBarDoubleClickedOnTab(tabIndex); + return true; + } else { + // standard event processing + return QTabWidget::eventFilter(obj, event); + } } diff --git a/ztabwidget.h b/ztabwidget.h index e70ba9f..1a6bfba 100644 --- a/ztabwidget.h +++ b/ztabwidget.h @@ -3,6 +3,8 @@ #include +class ZTabBar; + class ZTabWidget : public QTabWidget { Q_OBJECT @@ -10,9 +12,17 @@ class ZTabWidget : public QTabWidget explicit ZTabWidget(QWidget *parent = 0); signals: + void tabBarDoubleClickedOnEmptySpace(); + void tabBarDoubleClickedOnTab(int); public slots: + +protected: + // For detecting working tab + bool eventFilter(QObject *obj, QEvent *event); +private: + ZTabBar *tabBar; }; #endif // ZTABWIDGET_H