Skip to content

Commit

Permalink
1) Add support for call changing note's name by double clicking on a …
Browse files Browse the repository at this point in the history
…note's tab;
  • Loading branch information
VanDerSam committed Jul 20, 2014
1 parent 7f5083a commit 7ef1d32
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
10 changes: 6 additions & 4 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
28 changes: 22 additions & 6 deletions notelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
}

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions notelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
//
Expand All @@ -65,6 +66,8 @@ private slots:
void tabPositionChanged();
void notesPathChanged();
void scanForNewFiles();
void changeNoteName(int);

signals:
void currentNoteChanged(int old_index, int new_index);

Expand Down
4 changes: 1 addition & 3 deletions ztabbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ class ZTabBar : public QTabBar

public slots:


protected:
void paintEvent(QPaintEvent *);

void paintEvent(QPaintEvent *);
};

#endif // ZTABBAR_H
26 changes: 25 additions & 1 deletion ztabwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
#include <QMouseEvent>
#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<QMouseEvent *>(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);
}
}
10 changes: 10 additions & 0 deletions ztabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@

#include <QTabWidget>

class ZTabBar;

class ZTabWidget : public QTabWidget
{
Q_OBJECT
public:
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

0 comments on commit 7ef1d32

Please sign in to comment.