1
/***************************************************************************
2
File : RenameWindowDialog.cpp
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief, Tilman Benkert
6
Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
7
Description : Rename window dialog
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
29
#include "RenameWindowDialog.h"
30
#include "ApplicationWindow.h"
33
#include <QPushButton>
37
#include <QRadioButton>
38
#include <QMessageBox>
39
#include <QButtonGroup>
41
#include <QHBoxLayout>
42
#include <QGridLayout>
44
RenameWindowDialog::RenameWindowDialog(QWidget* parent, Qt::WFlags fl )
45
: QDialog( parent, fl )
47
setWindowTitle(tr("Rename Window"));
49
QGridLayout * leftLayout = new QGridLayout();
50
QVBoxLayout * rightLayout = new QVBoxLayout();
52
groupBox1 = new QGroupBox(tr("Window Title"));
53
groupBox1->setLayout(leftLayout);
55
boxName = new QRadioButton(tr("&Name (single word)"));
56
leftLayout->addWidget(boxName, 0, 0);
57
boxNameLine = new QLineEdit();
58
leftLayout->addWidget(boxNameLine, 0, 1);
59
setFocusProxy(boxNameLine);
61
boxLabel = new QRadioButton(tr("&Label"));
62
leftLayout->addWidget(boxLabel, 2, 0);
63
boxLabelEdit = new QTextEdit();
64
leftLayout->addWidget(boxLabelEdit, 1, 1, 3, 1);
65
boxLabelEdit->setMaximumHeight(100);
66
boxLabelEdit->setMinimumHeight(100);
68
boxBoth = new QRadioButton(tr("&Both Name and Label"));
69
leftLayout->addWidget(boxBoth, 4, 0);
71
buttons = new QButtonGroup(this);
72
buttons->addButton(boxName);
73
buttons->addButton(boxLabel);
74
buttons->addButton(boxBoth);
76
buttonOk = new QPushButton(tr( "&OK" ));
77
buttonOk->setAutoDefault( true );
78
buttonOk->setDefault( true );
79
rightLayout->addWidget(buttonOk);
81
buttonCancel = new QPushButton(tr( "&Cancel" ));
82
buttonCancel->setAutoDefault( true );
83
rightLayout->addWidget(buttonCancel);
84
rightLayout->addStretch();
86
QHBoxLayout * mainLayout = new QHBoxLayout(this);
87
mainLayout->addWidget(groupBox1);
88
mainLayout->addLayout(rightLayout);
90
// signals and slots connections
91
connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
92
connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
95
void RenameWindowDialog::setWidget(MyWidget *w)
98
boxNameLine->setText(w->name());
99
boxLabelEdit->setText(w->windowLabel());
100
switch (w->captionPolicy())
103
boxName->setChecked(true);
106
case MyWidget::Label:
107
boxLabel->setChecked(true);
111
boxBoth->setChecked(true);
116
MyWidget::CaptionPolicy RenameWindowDialog::getCaptionPolicy()
118
MyWidget::CaptionPolicy policy = MyWidget::Name;
119
if (boxLabel->isChecked())
120
policy = MyWidget::Label;
121
else if (boxBoth->isChecked())
122
policy = MyWidget::Both;
127
void RenameWindowDialog::accept()
129
QString name = window->name();
130
QString text = boxNameLine->text().remove("=").remove(QRegExp("\\s"));
131
QString label = boxLabelEdit->text();
133
MyWidget::CaptionPolicy policy = getCaptionPolicy();
134
if (text == name && label == window->windowLabel() && window->captionPolicy() == policy)
137
ApplicationWindow *app = (ApplicationWindow *)parentWidget();
141
if (text.contains("_")){
142
QMessageBox::warning(this, tr("Warning"),
143
tr("For internal consistency reasons the underscore character is replaced with a minus sign."));}
145
if (text.replace("_", "-") != name){
146
if(!app->renameWindow(window, text))
150
label.replace("\n"," ").replace("\t"," ");
151
window->setWindowLabel(label);
152
window->setCaptionPolicy(policy);
153
app->setListViewLabel(window->name(), label);
154
app->modifiedProject(window);