1 /***************************************************************************
2 * Copyright (C) 2005-2009 by Rajko Albrecht *
3 * ral@alwins-world.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #include "rangeinput_impl.h"
21 #include <QPointer>
22 #include <ksvnwidgets/ksvndialog.h>
23
Rangeinput_impl(QWidget * parent)24 Rangeinput_impl::Rangeinput_impl(QWidget *parent)
25 : QWidget(parent)
26 , m_StartOnly(false)
27 {
28 setupUi(this);
29
30 m_startRevInput->setRange(0, INT_MAX);
31 m_startRevInput->setSingleStep(1);
32 m_startRevInput->setValue(1);
33 m_endRevInput->setRange(0, INT_MAX);
34 m_endRevInput->setSingleStep(1);
35 m_endRevInput->setValue(1);
36 m_startDateInput->setDateTime(QDateTime::currentDateTime());
37 m_stopDateInput->setDateTime(QDateTime::currentDateTime());
38 m_stopDateInput->setEnabled(false);
39 m_startDateInput->setEnabled(false);
40 m_stopHeadButton->setChecked(true);
41
42 const int minHeight = qMax(m_startRevInput->height(), m_startDateInput->height());
43 m_startNumberButton->setMinimumHeight(minHeight);
44 m_startDateButton->setMinimumHeight(minHeight);
45 m_startStartButton->setMinimumHeight(minHeight);
46 m_startHeadButton->setMinimumHeight(minHeight);
47 m_startWorkingButton->setMinimumHeight(minHeight);
48 m_stopNumberButton->setMinimumHeight(minHeight);
49 m_stopDateButton->setMinimumHeight(minHeight);
50 m_stopStartButton->setMinimumHeight(minHeight);
51 m_stopHeadButton->setMinimumHeight(minHeight);
52 m_stopWorkingButton->setMinimumHeight(minHeight);
53 }
54
getRevisionRange(revision_range & range,bool bWithWorking,bool bStartOnly,const svn::Revision & preset,QWidget * parent)55 bool Rangeinput_impl::getRevisionRange(revision_range &range,
56 bool bWithWorking,
57 bool bStartOnly,
58 const svn::Revision &preset,
59 QWidget *parent)
60 {
61 QPointer<KSvnSimpleOkDialog> dlg(new KSvnSimpleOkDialog(QStringLiteral("revisions_dlg"), parent));
62 dlg->setWindowTitle(i18nc("@title:window", "Select Revisions"));
63 dlg->setWithCancelButton();
64 Rangeinput_impl *rdlg(new Rangeinput_impl(dlg));
65 rdlg->setNoWorking(!bWithWorking);
66 rdlg->setStartOnly(bStartOnly);
67 rdlg->m_startRevInput->setValue(preset.revnum());
68 dlg->addWidget(rdlg);
69 if (dlg->exec() == QDialog::Accepted) {
70 range = rdlg->getRange();
71 delete dlg;
72 return true;
73 }
74 delete dlg;
75 return false;
76 }
77
startNumberToggled(bool how)78 void Rangeinput_impl::startNumberToggled(bool how)
79 {
80 m_startRevInput->setEnabled(how);
81 if (how) {
82 m_startDateInput->setEnabled(!how);
83 }
84 }
85
startBaseToggled(bool how)86 void Rangeinput_impl::startBaseToggled(bool how)
87 {
88 if (how) {
89 m_startRevInput->setEnabled(!how);
90 m_startDateInput->setEnabled(!how);
91 }
92 }
93
startHeadToggled(bool how)94 void Rangeinput_impl::startHeadToggled(bool how)
95 {
96 if (how) {
97 m_startRevInput->setEnabled(!how);
98 m_startDateInput->setEnabled(!how);
99 }
100 }
101
setNoWorking(bool aValue)102 void Rangeinput_impl::setNoWorking(bool aValue)
103 {
104 if (!aValue) {
105 if (m_startWorkingButton->isChecked()) {
106 m_startHeadButton->setChecked(false);
107 }
108 if (m_stopWorkingButton->isChecked()) {
109 m_stopHeadButton->setChecked(false);
110 }
111 }
112 m_startWorkingButton->setEnabled(!aValue);
113 m_stopWorkingButton->setEnabled(!aValue);
114 }
115
onHelp()116 void Rangeinput_impl::onHelp()
117 {
118 }
119
stopHeadToggled(bool how)120 void Rangeinput_impl::stopHeadToggled(bool how)
121 {
122 if (how) {
123 m_endRevInput->setEnabled(!how);
124 m_stopDateInput->setEnabled(!how);
125 }
126 }
127
stopBaseToggled(bool how)128 void Rangeinput_impl::stopBaseToggled(bool how)
129 {
130 if (how) {
131 m_endRevInput->setEnabled(!how);
132 m_stopDateInput->setEnabled(!how);
133 }
134 }
135
stopNumberToggled(bool how)136 void Rangeinput_impl::stopNumberToggled(bool how)
137 {
138 m_endRevInput->setEnabled(how);
139 if (how) {
140 m_stopDateInput->setEnabled(!how);
141 }
142 }
143
getRange() const144 Rangeinput_impl::revision_range Rangeinput_impl::getRange() const
145 {
146 revision_range ret;
147 if (m_startStartButton->isChecked()) {
148 ret.first = svn::Revision::START;
149 } else if (m_startHeadButton->isChecked()) {
150 ret.first = svn::Revision::HEAD;
151 } else if (m_startNumberButton->isChecked()) {
152 ret.first = m_startRevInput->value();
153 } else if (m_startDateButton->isChecked()) {
154 ret.first = m_startDateInput->dateTime();
155 } else if (m_startWorkingButton->isChecked()) {
156 ret.first = svn::Revision::WORKING;
157 }
158 if (m_stopStartButton->isChecked()) {
159 ret.second = svn::Revision::START;
160 } else if (m_stopHeadButton->isChecked()) {
161 ret.second = svn::Revision::HEAD;
162 } else if (m_stopNumberButton->isChecked()) {
163 ret.second = m_endRevInput->value();
164 } else if (m_stopDateButton->isChecked()) {
165 ret.second = m_stopDateInput->dateTime();
166 } else if (m_stopWorkingButton->isChecked()) {
167 ret.second = svn::Revision::WORKING;
168 }
169 return ret;
170 }
171
stopDateToggled(bool how)172 void Rangeinput_impl::stopDateToggled(bool how)
173 {
174 m_stopDateInput->setEnabled(how);
175 if (how) {
176 m_endRevInput->setEnabled(!how);
177 }
178 }
179
startDateToggled(bool how)180 void Rangeinput_impl::startDateToggled(bool how)
181 {
182 m_startDateInput->setEnabled(how);
183 if (how) {
184 m_startRevInput->setEnabled(!how);
185 }
186 }
187
StartOnly() const188 bool Rangeinput_impl::StartOnly() const
189 {
190 return m_StartOnly;
191 }
192
setHeadDefault()193 void Rangeinput_impl::setHeadDefault()
194 {
195 m_stopHeadButton->setChecked(true);
196 m_startHeadButton->setChecked(true);
197 }
198
setStartOnly(bool theValue)199 void Rangeinput_impl::setStartOnly(bool theValue)
200 {
201 m_StartOnly = theValue;
202 if (m_StartOnly) {
203 layout()->removeWidget(m_stopRevBox);
204 m_stopRevBox->hide();
205 m_startRevBox->setTitle(i18n("Select revision"));
206 } else {
207 layout()->addWidget(m_stopRevBox);
208 m_stopRevBox->show();
209 m_startRevBox->setTitle(i18n("Start with revision"));
210 }
211 updateGeometry();
212 setMinimumSize(minimumSizeHint());
213 resize(QSize(397, 272).expandedTo(minimumSizeHint()));
214 }
215