~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/RenameWindowDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : RenameWindowDialog.cpp
 
3
    Project              : SciDAVis
 
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
 
8
                           
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
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.                                    *
 
17
 *                                                                         *
 
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.                           *
 
22
 *                                                                         *
 
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                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#include "RenameWindowDialog.h"
 
30
#include "ApplicationWindow.h"
 
31
#include "Table.h"
 
32
 
 
33
#include <QPushButton>
 
34
#include <QGroupBox>
 
35
#include <QLineEdit>
 
36
#include <QTextEdit>
 
37
#include <QRadioButton>
 
38
#include <QMessageBox>
 
39
#include <QButtonGroup>
 
40
#include <QRegExp>
 
41
#include <QHBoxLayout>
 
42
#include <QGridLayout>
 
43
 
 
44
RenameWindowDialog::RenameWindowDialog(QWidget* parent, Qt::WFlags fl )
 
45
    : QDialog( parent, fl )
 
46
{
 
47
        setWindowTitle(tr("Rename Window"));
 
48
 
 
49
        QGridLayout * leftLayout = new QGridLayout();
 
50
        QVBoxLayout * rightLayout = new QVBoxLayout();
 
51
 
 
52
        groupBox1 = new QGroupBox(tr("Window Title"));
 
53
        groupBox1->setLayout(leftLayout);
 
54
 
 
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);
 
60
 
 
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);
 
67
 
 
68
        boxBoth = new QRadioButton(tr("&Both Name and Label"));
 
69
        leftLayout->addWidget(boxBoth, 4, 0);
 
70
        
 
71
        buttons = new QButtonGroup(this);
 
72
        buttons->addButton(boxName);
 
73
        buttons->addButton(boxLabel);
 
74
        buttons->addButton(boxBoth);
 
75
        
 
76
        buttonOk = new QPushButton(tr( "&OK" ));
 
77
    buttonOk->setAutoDefault( true );
 
78
    buttonOk->setDefault( true );
 
79
        rightLayout->addWidget(buttonOk);
 
80
   
 
81
    buttonCancel = new QPushButton(tr( "&Cancel" ));
 
82
    buttonCancel->setAutoDefault( true );
 
83
        rightLayout->addWidget(buttonCancel);
 
84
        rightLayout->addStretch();
 
85
        
 
86
        QHBoxLayout * mainLayout = new QHBoxLayout(this);
 
87
    mainLayout->addWidget(groupBox1);
 
88
        mainLayout->addLayout(rightLayout);
 
89
 
 
90
    // signals and slots connections
 
91
    connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
 
92
    connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
 
93
}
 
94
 
 
95
void RenameWindowDialog::setWidget(MyWidget *w)
 
96
{
 
97
        window = w;
 
98
        boxNameLine->setText(w->name());
 
99
        boxLabelEdit->setText(w->windowLabel());
 
100
        switch (w->captionPolicy())
 
101
        {
 
102
                case MyWidget::Name:
 
103
                        boxName->setChecked(true);
 
104
                        break;
 
105
 
 
106
                case MyWidget::Label:
 
107
                        boxLabel->setChecked(true);
 
108
                        break;
 
109
 
 
110
                case MyWidget::Both:
 
111
                        boxBoth->setChecked(true);
 
112
                        break;
 
113
        }
 
114
}
 
115
 
 
116
MyWidget::CaptionPolicy RenameWindowDialog::getCaptionPolicy()
 
117
{
 
118
        MyWidget::CaptionPolicy policy = MyWidget::Name;
 
119
        if (boxLabel->isChecked())
 
120
                policy = MyWidget::Label;
 
121
        else if (boxBoth->isChecked())
 
122
                policy = MyWidget::Both;
 
123
 
 
124
        return policy;
 
125
}
 
126
 
 
127
void RenameWindowDialog::accept()
 
128
{
 
129
        QString name = window->name();
 
130
        QString text = boxNameLine->text().remove("=").remove(QRegExp("\\s"));
 
131
        QString label = boxLabelEdit->text();
 
132
 
 
133
        MyWidget::CaptionPolicy policy = getCaptionPolicy();
 
134
        if (text == name && label == window->windowLabel() && window->captionPolicy() == policy)
 
135
                close();
 
136
 
 
137
        ApplicationWindow *app = (ApplicationWindow *)parentWidget();
 
138
        if (!app)
 
139
                return;
 
140
 
 
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."));}
 
144
         
 
145
        if (text.replace("_", "-") != name){
 
146
                if(!app->renameWindow(window, text))
 
147
                        return;
 
148
        }
 
149
 
 
150
        label.replace("\n"," ").replace("\t"," ");
 
151
        window->setWindowLabel(label);
 
152
        window->setCaptionPolicy(policy);
 
153
        app->setListViewLabel(window->name(), label);
 
154
        app->modifiedProject(window);
 
155
        close();
 
156
}