Diffstat (limited to 'noncore/apps/confedit/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 77b91f6..17a5058 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp | |||
@@ -37,74 +37,97 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | |||
37 | QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0) | 37 | QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0) |
38 | { | 38 | { |
39 | setCaption( tr("Conf File Editor") ); | 39 | setCaption( tr("Conf File Editor") ); |
40 | 40 | ||
41 | QWidget *mainWidget = new QWidget(this); | 41 | QWidget *mainWidget = new QWidget(this); |
42 | setCentralWidget( mainWidget); | 42 | setCentralWidget( mainWidget); |
43 | |||
44 | QGridLayout *mainLayout = new QGridLayout( mainWidget ); | 43 | QGridLayout *mainLayout = new QGridLayout( mainWidget ); |
45 | mainLayout->setSpacing( 3 ); | 44 | mainLayout->setSpacing( 3 ); |
46 | mainLayout->setMargin( 3 ); | 45 | mainLayout->setMargin( 3 ); |
47 | 46 | ||
48 | 47 | ||
48 | qDebug("settingList"); | ||
49 | settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); | 49 | settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); |
50 | settingList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding));//, sizePolicy().hasHeightForWidth() ) ); | ||
50 | mainLayout->addWidget( settingList, 0, 0 ); | 51 | mainLayout->addWidget( settingList, 0, 0 ); |
51 | 52 | ||
53 | qDebug("editor"); | ||
52 | editor = new EditWidget(this); | 54 | editor = new EditWidget(this); |
55 | editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum));//, sizePolicy().hasHeightForWidth() ) ); | ||
56 | // editor->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3));//, sizePolicy().hasHeightForWidth() ) ); | ||
53 | mainLayout->addWidget( editor, 1, 0 ); | 57 | mainLayout->addWidget( editor, 1, 0 ); |
54 | 58 | ||
59 | makeMenu(); | ||
60 | |||
61 | qDebug("connect"); | ||
55 | connect(settingList, SIGNAL( pressed(QListViewItem*) ), | 62 | connect(settingList, SIGNAL( pressed(QListViewItem*) ), |
56 | this, SLOT(setCurrent(QListViewItem*))); | 63 | this, SLOT(setCurrent(QListViewItem*))); |
57 | 64 | ||
58 | 65 | ||
59 | connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), | 66 | connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), |
60 | SLOT( groupChanged(const QString&) ) ); | 67 | SLOT( groupChanged(const QString&) ) ); |
61 | connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), | 68 | connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), |
62 | SLOT( keyChanged(const QString&) ) ); | 69 | SLOT( keyChanged(const QString&) ) ); |
63 | connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), | 70 | connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), |
64 | SLOT( valueChanged(const QString&) ) ); | 71 | SLOT( valueChanged(const QString&) ) ); |
65 | makeMenu(); | 72 | // qDebug("editor->hide()"); |
73 | // editor->hide(); | ||
74 | qDebug("connect"); | ||
75 | connect( settingList, SIGNAL( clicked( QListViewItem* ) ), | ||
76 | this, SLOT( stopTimer( QListViewItem* ) ) ); | ||
66 | } | 77 | } |
67 | 78 | ||
68 | void MainWindow::makeMenu() | 79 | void MainWindow::makeMenu() |
69 | { | 80 | { |
70 | 81 | qDebug("MainWindow::makeMenu()"); | |
71 | 82 | ||
72 | popupTimer = new QTimer(this); | 83 | popupTimer = new QTimer(this); |
73 | popupMenuFile = new QPopupMenu(this); | 84 | popupMenuFile = new QPopupMenu(this); |
85 | popupMenuEntry = new QPopupMenu(this); | ||
74 | 86 | ||
87 | qDebug("Save"); | ||
75 | popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); | 88 | popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); |
76 | popupActionSave->addTo( popupMenuFile ); | 89 | popupActionSave->addTo( popupMenuFile ); |
90 | // popupActionSave->addTo( popupMenuEntry ); | ||
77 | connect( popupActionSave, SIGNAL( activated() ), | 91 | connect( popupActionSave, SIGNAL( activated() ), |
78 | this , SLOT( saveConfFile() ) ); | 92 | this , SLOT( saveConfFile() ) ); |
93 | |||
94 | qDebug("Revert"); | ||
79 | popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); | 95 | popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); |
80 | popupActionRevert->addTo( popupMenuFile ); | 96 | popupActionRevert->addTo( popupMenuFile ); |
97 | popupActionRevert->addTo( popupMenuEntry ); | ||
81 | connect( popupActionRevert, SIGNAL( activated() ), | 98 | connect( popupActionRevert, SIGNAL( activated() ), |
82 | this , SLOT( revertConfFile() ) ); | 99 | this , SLOT( revertConfFile() ) ); |
83 | 100 | ||
101 | qDebug("Delete"); | ||
102 | popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 ); | ||
103 | popupActionDelete->addTo( popupMenuFile ); | ||
104 | popupActionDelete->addTo( popupMenuEntry ); | ||
105 | connect( popupActionDelete, SIGNAL( activated() ), | ||
106 | this , SLOT( removeConfFile() ) ); | ||
107 | |||
108 | qDebug("connect"); | ||
84 | connect( popupTimer, SIGNAL(timeout()), | 109 | connect( popupTimer, SIGNAL(timeout()), |
85 | this, SLOT(showPopup()) ); | 110 | this, SLOT(showPopup()) ); |
86 | connect( settingList, SIGNAL( clicked( QListViewItem* ) ), | 111 | qDebug("connect"); |
87 | this, SLOT( stopTimer( QListViewItem* ) ) ); | ||
88 | } | 112 | } |
89 | 113 | ||
90 | MainWindow::~MainWindow() | 114 | MainWindow::~MainWindow() |
91 | { | 115 | { |
92 | } | 116 | } |
93 | 117 | ||
94 | 118 | ||
95 | 119 | ||
96 | void MainWindow::setCurrent(QListViewItem *item) | 120 | void MainWindow::setCurrent(QListViewItem *item) |
97 | { | 121 | { |
98 | if (!item) return; | 122 | if (!item) return; |
99 | ListViewItemConf *i = (ListViewItemConf*) item; | 123 | _item = (ListViewItemConf*) item; |
100 | if (!i) return; | 124 | if (!_item) return; |
101 | if (i->getType() == ListViewItemConf::File) | ||
102 | { | ||
103 | qDebug("start timer"); | ||
104 | popupTimer->start( 750, true ); | 125 | popupTimer->start( 750, true ); |
126 | if (_item->getType() == ListViewItemConf::File) | ||
127 | { | ||
105 | editor->hide(); | 128 | editor->hide(); |
106 | updateGeometry(); | 129 | updateGeometry(); |
107 | _currentItem=0; | 130 | _currentItem=0; |
108 | _fileItem = (ListViewItemConfFile*)item; | 131 | _fileItem = (ListViewItemConfFile*)item; |
109 | return; | 132 | return; |
110 | }else editor->show(); | 133 | }else editor->show(); |
@@ -123,12 +146,14 @@ void MainWindow::setCurrent(QListViewItem *item) | |||
123 | editor->LineEditKey->setText(key); | 146 | editor->LineEditKey->setText(key); |
124 | editor->LineEditValue->setText(val); | 147 | editor->LineEditValue->setText(val); |
125 | }else{ | 148 | }else{ |
126 | editor->isKey(false); | 149 | editor->isKey(false); |
127 | } | 150 | } |
128 | updateGeometry(); | 151 | updateGeometry(); |
152 | editor->updateGeometry(); | ||
153 | settingList->updateGeometry(); | ||
129 | } | 154 | } |
130 | 155 | ||
131 | 156 | ||
132 | void MainWindow::groupChanged(const QString &g) | 157 | void MainWindow::groupChanged(const QString &g) |
133 | { | 158 | { |
134 | if (!_currentItem) return; | 159 | if (!_currentItem) return; |
@@ -147,35 +172,41 @@ void MainWindow::valueChanged(const QString &v) | |||
147 | _currentItem->valueChanged(v); | 172 | _currentItem->valueChanged(v); |
148 | } | 173 | } |
149 | 174 | ||
150 | 175 | ||
151 | void MainWindow::stopTimer( QListViewItem* ) | 176 | void MainWindow::stopTimer( QListViewItem* ) |
152 | { | 177 | { |
153 | qDebug("stopTimer"); | ||
154 | popupTimer->stop(); | 178 | popupTimer->stop(); |
155 | } | 179 | } |
156 | 180 | ||
157 | void MainWindow::saveConfFile() | 181 | void MainWindow::saveConfFile() |
158 | { | 182 | { |
159 | if (!_fileItem) return; | 183 | if (!_fileItem) return; |
160 | _fileItem->save(); | 184 | _fileItem->save(); |
161 | } | 185 | } |
162 | 186 | ||
163 | void MainWindow::revertConfFile() | 187 | void MainWindow::revertConfFile() |
164 | { | 188 | { |
165 | if (!_fileItem) return; | 189 | if (!_item) return; |
166 | _fileItem->revert(); | 190 | _item->revert(); |
167 | } | 191 | } |
168 | 192 | ||
193 | void MainWindow::removeConfFile() | ||
194 | { | ||
195 | if (!_item) return; | ||
196 | _item->remove(); | ||
197 | } | ||
169 | void MainWindow::showPopup() | 198 | void MainWindow::showPopup() |
170 | { | 199 | { |
171 | qDebug("showPopup"); | 200 | qDebug("showPopup"); |
201 | if (!_item) return; | ||
202 | popupActionRevert->setEnabled(_item->revertable()); | ||
203 | popupActionSave->setEnabled(_item->isChanged()); | ||
172 | if (_fileItem) | 204 | if (_fileItem) |
173 | { | 205 | { |
174 | popupActionSave->setEnabled(_fileItem->isChanged()); | 206 | popupActionSave->setEnabled(_fileItem->isChanged()); |
175 | popupActionRevert->setEnabled(_fileItem->revertable()); | ||
176 | popupMenuFile->popup( QCursor::pos() ); | 207 | popupMenuFile->popup( QCursor::pos() ); |
177 | }else if(_currentItem->isChanged()) | 208 | }else if(_currentItem) |
178 | { | 209 | { |
179 | 210 | popupMenuEntry->popup( QCursor::pos() ); | |
180 | } | 211 | } |
181 | } | 212 | } |