summaryrefslogtreecommitdiff
path: root/utils/regtools/qeditor/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/regtools/qeditor/mainwindow.cpp')
-rw-r--r--utils/regtools/qeditor/mainwindow.cpp63
1 files changed, 56 insertions, 7 deletions
diff --git a/utils/regtools/qeditor/mainwindow.cpp b/utils/regtools/qeditor/mainwindow.cpp
index 2ba781b042..cd0926851c 100644
--- a/utils/regtools/qeditor/mainwindow.cpp
+++ b/utils/regtools/qeditor/mainwindow.cpp
@@ -12,6 +12,7 @@
12 12
13#include "mainwindow.h" 13#include "mainwindow.h"
14#include "regtab.h" 14#include "regtab.h"
15#include "regedit.h"
15 16
16MyTabWidget::MyTabWidget() 17MyTabWidget::MyTabWidget()
17{ 18{
@@ -20,23 +21,37 @@ MyTabWidget::MyTabWidget()
20 connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(OnCloseTab(int))); 21 connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(OnCloseTab(int)));
21} 22}
22 23
23void MyTabWidget::OnCloseTab(int index) 24bool MyTabWidget::CloseTab(int index)
24{ 25{
25 QWidget *w = this->widget(index); 26 QWidget *w = this->widget(index);
26 removeTab(index); 27 DocumentTab *doc = dynamic_cast< DocumentTab* >(w);
27 delete w; 28 if(doc->Quit())
29 {
30 removeTab(index);
31 delete w;
32 return true;
33 }
34 else
35 return false;
36}
37
38void MyTabWidget::OnCloseTab(int index)
39{
40 CloseTab(index);
28} 41}
29 42
30MainWindow::MainWindow(Backend *backend) 43MainWindow::MainWindow(Backend *backend)
31 :m_backend(backend) 44 :m_backend(backend)
32{ 45{
33 QAction *new_regtab_act = new QAction(QIcon::fromTheme("document-new"), tr("&Register Tab"), this); 46 QAction *new_regtab_act = new QAction(QIcon::fromTheme("document-new"), tr("Register &Tab"), this);
47 QAction *new_regedit_act = new QAction(QIcon::fromTheme("document-edit"), tr("Register &Editor"), this);
34 QAction *load_desc_act = new QAction(QIcon::fromTheme("document-open"), tr("&Soc Description"), this); 48 QAction *load_desc_act = new QAction(QIcon::fromTheme("document-open"), tr("&Soc Description"), this);
35 QAction *quit_act = new QAction(QIcon::fromTheme("application-exit"), tr("&Quit"), this); 49 QAction *quit_act = new QAction(QIcon::fromTheme("application-exit"), tr("&Quit"), this);
36 QAction *about_act = new QAction(QIcon::fromTheme("help-about"), tr("&About"), this); 50 QAction *about_act = new QAction(QIcon::fromTheme("help-about"), tr("&About"), this);
37 QAction *about_qt_act = new QAction(QIcon::fromTheme("help-about"), tr("About &Qt"), this); 51 QAction *about_qt_act = new QAction(QIcon::fromTheme("help-about"), tr("About &Qt"), this);
38 52
39 connect(new_regtab_act, SIGNAL(triggered()), this, SLOT(OnNewRegTab())); 53 connect(new_regtab_act, SIGNAL(triggered()), this, SLOT(OnNewRegTab()));
54 connect(new_regedit_act, SIGNAL(triggered()), this, SLOT(OnNewRegEdit()));
40 connect(load_desc_act, SIGNAL(triggered()), this, SLOT(OnLoadDesc())); 55 connect(load_desc_act, SIGNAL(triggered()), this, SLOT(OnLoadDesc()));
41 connect(quit_act, SIGNAL(triggered()), this, SLOT(OnQuit())); 56 connect(quit_act, SIGNAL(triggered()), this, SLOT(OnQuit()));
42 connect(about_act, SIGNAL(triggered()), this, SLOT(OnAbout())); 57 connect(about_act, SIGNAL(triggered()), this, SLOT(OnAbout()));
@@ -48,6 +63,7 @@ MainWindow::MainWindow(Backend *backend)
48 file_menu->addAction(quit_act); 63 file_menu->addAction(quit_act);
49 64
50 new_submenu->addAction(new_regtab_act); 65 new_submenu->addAction(new_regtab_act);
66 new_submenu->addAction(new_regedit_act);
51 67
52 load_submenu->addAction(load_desc_act); 68 load_submenu->addAction(load_desc_act);
53 69
@@ -91,6 +107,8 @@ void MainWindow::OnAboutQt()
91 107
92void MainWindow::closeEvent(QCloseEvent *event) 108void MainWindow::closeEvent(QCloseEvent *event)
93{ 109{
110 if(!Quit())
111 return event->ignore();
94 WriteSettings(); 112 WriteSettings();
95 event->accept(); 113 event->accept();
96} 114}
@@ -100,7 +118,7 @@ void MainWindow::OnLoadDesc()
100 QFileDialog *fd = new QFileDialog(this); 118 QFileDialog *fd = new QFileDialog(this);
101 fd->setFilter("XML files (*.xml);;All files (*)"); 119 fd->setFilter("XML files (*.xml);;All files (*)");
102 fd->setFileMode(QFileDialog::ExistingFiles); 120 fd->setFileMode(QFileDialog::ExistingFiles);
103 fd->setDirectory(Settings::Get()->value("mainwindow/loaddescdir", QDir::currentPath()).toString()); 121 fd->setDirectory(Settings::Get()->value("loaddescdir", QDir::currentPath()).toString());
104 if(fd->exec()) 122 if(fd->exec())
105 { 123 {
106 QStringList filenames = fd->selectedFiles(); 124 QStringList filenames = fd->selectedFiles();
@@ -111,11 +129,42 @@ void MainWindow::OnLoadDesc()
111 msg.setText(QString("Cannot load ") + filenames[i]); 129 msg.setText(QString("Cannot load ") + filenames[i]);
112 msg.exec(); 130 msg.exec();
113 } 131 }
114 Settings::Get()->setValue("mainwindow/loaddescdir", fd->directory().absolutePath()); 132 Settings::Get()->setValue("loaddescdir", fd->directory().absolutePath());
115 } 133 }
116} 134}
117 135
136void MainWindow::OnTabModified(bool modified)
137{
138 QWidget *sender = qobject_cast< QWidget* >(QObject::sender());
139 int index = m_tab->indexOf(sender);
140 if(modified)
141 m_tab->setTabIcon(index, QIcon::fromTheme("document-save"));
142 else
143 m_tab->setTabIcon(index, QIcon());
144}
145
146void MainWindow::AddTab(QWidget *tab, const QString& title)
147{
148 connect(tab, SIGNAL(OnModified(bool)), this, SLOT(OnTabModified(bool)));
149 m_tab->setCurrentIndex(m_tab->addTab(tab, title));
150}
151
118void MainWindow::OnNewRegTab() 152void MainWindow::OnNewRegTab()
119{ 153{
120 m_tab->addTab(new RegTab(m_backend), "Register Tab"); 154 AddTab(new RegTab(m_backend, this), "Register Tab");
155}
156
157void MainWindow::OnNewRegEdit()
158{
159 AddTab(new RegEdit(m_backend, this), "Register Editor");
160}
161
162bool MainWindow::Quit()
163{
164 while(m_tab->count() > 0)
165 {
166 if(!m_tab->CloseTab(0))
167 return false;
168 }
169 return true;
121} 170}