Skip to content

Commit 90e7e62

Browse files
committed
0.3.0b
1 parent 55c37d2 commit 90e7e62

File tree

9 files changed

+72
-9
lines changed

9 files changed

+72
-9
lines changed

mainwindow.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <QMessageBox>
1010
#include <QFileDialog>
1111
#include <QClipboard>
12+
#include <QProcess>
1213

1314
Settings settings;
1415

@@ -230,16 +231,37 @@ void MainWindow::noteFontChanged()
230231
}
231232
}
232233

234+
void MainWindow::commandMenu()
235+
{
236+
QPoint p = ui->mainToolBar->actionGeometry(&cmd_action).center();
237+
p+=pos();
238+
cmd_menu.exec(p);
239+
}
240+
241+
void MainWindow::cmdExec(const QString & command)
242+
{
243+
QProcess p;
244+
QStringList args;
245+
args << dir.absoluteFilePath(currentNote()->file.fileName());
246+
p.start(command, args);
247+
if(p.waitForStarted())
248+
{
249+
if(p.waitForFinished(10000))
250+
{
251+
QByteArray result = p.readAll();
252+
tray.showMessage(command, QString::fromUtf8(result));
253+
}
254+
}
255+
}
256+
233257
MainWindow::MainWindow(QWidget *parent)
234-
: QMainWindow(parent), ui(new Ui::MainWindow), CurrentIndex(-1)
258+
: QMainWindow(parent), ui(new Ui::MainWindow), CurrentIndex(-1), cmd_action(QIcon(":/res/exec.png"), tr("Commands"), parent)
235259
{
236260
ui->setupUi(this);
237261
//
238262
restoreGeometry(settings.getDialogGeometry());
239263
windowStateChanged();
240264
//
241-
//ui->mainToolBar->setOrientation(Qt::Vertical);
242-
ui->mainToolBar->setContextMenuPolicy(Qt::NoContextMenu);
243265
ui->mainToolBar->addAction(QIcon(":/res/add.png"), tr("Create new note"),
244266
this, SLOT(NewNote()));
245267
ui->mainToolBar->addAction(QIcon(":/res/remove.png"), tr("Remove this note"),
@@ -257,9 +279,20 @@ MainWindow::MainWindow(QWidget *parent)
257279
ui->mainToolBar->addSeparator();
258280
ui->mainToolBar->addAction(QIcon(":/res/settings.png"), tr("Preferences"),
259281
this, SLOT(prefDialog()));
282+
ui->mainToolBar->addSeparator();
283+
ui->mainToolBar->addAction(&cmd_action);
284+
connect(&cmd_action, SIGNAL(triggered()), this, SLOT(commandMenu()));
260285
ui->mainToolBar->actions()[0]->setShortcut(QKeySequence::New);
261286
ui->mainToolBar->actions()[1]->setShortcut(QKeySequence::Delete);
262287
//
288+
const QVector<Script>& cmdlist = settings.getComandList();
289+
for(int i=0; i<cmdlist.size(); ++i)
290+
{
291+
cmd_menu.addAction(QIcon(cmdlist[i].icon), cmdlist[i].name, &cmd_mapper, SLOT(map()));
292+
cmd_mapper.setMapping(cmd_menu.actions().last(), cmdlist[i].addr);
293+
connect(&cmd_mapper, SIGNAL(mapped(const QString &)), this, SLOT(cmdExec(const QString &)));
294+
}
295+
//
263296
cmenu.addAction(tr("Show"), this, SLOT(show()));
264297
cmenu.addAction(tr("Hide"), this, SLOT(hide()));
265298
cmenu.addSeparator();

mainwindow.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QSystemTrayIcon>
77
#include <QMenu>
88
#include <QTimer>
9+
#include <QSignalMapper>
910

1011
#include "note.h"
1112

@@ -32,6 +33,9 @@ class MainWindow : public QMainWindow
3233
int CurrentIndex;
3334
QSystemTrayIcon tray;
3435
QMenu cmenu;
36+
QAction cmd_action;
37+
QMenu cmd_menu;
38+
QSignalMapper cmd_mapper;
3539
QTimer SaveTimer;
3640
//
3741
void LoadNotes();
@@ -41,7 +45,7 @@ class MainWindow : public QMainWindow
4145
}
4246
int currentIndex;
4347
void SaveNote(int i);
44-
private slots:
48+
public slots:
4549
void SaveCurrentNote();
4650
void RemoveCurrentNote();
4751
void RenameCurrentNote();
@@ -59,12 +63,15 @@ private slots:
5963
//
6064
void trayActivated(QSystemTrayIcon::ActivationReason reason);
6165
//
66+
void commandMenu();
6267
void aboutDialog();
6368
void prefDialog();
6469
//
70+
void cmdExec(const QString &);
71+
//
6572
void notesPathChanged();
6673
void windowStateChanged();
67-
void toolbarVisChanged();
74+
void toolbarVisChanged();//TODO:подумать...
6875
void noteFontChanged();
6976
};
7077

mainwindow.ui

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>296</width>
10-
<height>396</height>
9+
<width>294</width>
10+
<height>394</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -43,6 +43,9 @@
4343
</layout>
4444
</widget>
4545
<widget class="QToolBar" name="mainToolBar">
46+
<property name="windowTitle">
47+
<string>Show Toolbar</string>
48+
</property>
4649
<property name="iconSize">
4750
<size>
4851
<width>16</width>

settings.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Settings::Settings() : config("pDev", "zNotes")
1515
StayTop = config.value("StayTop").toBool();
1616
//
1717
NoteFont.fromString(config.value("NoteFont").toString());
18+
//
19+
ComandList.resize(config.value("ComandCount").toInt());
20+
for(int i=0; i<ComandList.size(); ++i)
21+
{
22+
ComandList[i].name = config.value(QString("ComandName%1").arg(i)).toString();
23+
ComandList[i].icon = config.value(QString("ComandIcon%1").arg(i)).toString();
24+
ComandList[i].addr = config.value(QString("ComandFile%1").arg(i)).toString();
25+
}
1826
}
1927

2028
void Settings::setNotesPath(const QString& path)

settings.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#include <QPoint>
99
#include <QByteArray>
1010
#include <QFont>
11+
#include <QVector>
12+
13+
struct Script
14+
{
15+
QString name;
16+
QString icon;
17+
QString addr;
18+
};
1119

1220
class Settings : public QObject
1321
{
@@ -23,6 +31,7 @@ class Settings : public QObject
2331
inline bool getHideFrame() { return HideFrame; }
2432
inline bool getStayTop() { return StayTop; }
2533
inline const QFont& getNoteFont() { return NoteFont; }
34+
inline const QVector<Script>& getComandList() { return ComandList; }
2635
//
2736
void setNotesPath(const QString& path);
2837
void setLastNote(const QString& name);
@@ -46,6 +55,8 @@ class Settings : public QObject
4655
bool StayTop;
4756
//
4857
QFont NoteFont;
58+
//
59+
QVector<Script> ComandList;
4960
signals:
5061
void NotesPathChanged();
5162
void WindowStateChanged();

translations/znotes_ru.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Do you want to move your notes to new place ?</source>
102102
<message>
103103
<location filename="../mainwindow.cpp" line="255"/>
104104
<source>Copy this note to clipboard</source>
105-
<translation>Копировать содержимое в буффер обмена</translation>
105+
<translation>Скопировать содержимое в буффер обмена</translation>
106106
</message>
107107
<message>
108108
<location filename="../mainwindow.cpp" line="258"/>

znotes.png

1.38 KB
Loading

znotes.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Project created by QtCreator 2009-09-20T17:20:55
33
# -------------------------------------------------
44
TARGET = znotes
5-
VERSION = 0.2.7
5+
VERSION = 0.3.0
66
QT += core \
77
gui
88
TEMPLATE = app

znotes.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<file>res/copy.png</file>
1313
<file>res/next.png</file>
1414
<file>res/prev.png</file>
15+
<file>res/exec.png</file>
1516
</qresource>
1617
</RCC>

0 commit comments

Comments
 (0)