Commit a30478a7 authored by André Wöbbeking's avatar André Wöbbeking
Browse files

- Inherit from KDialogBase instead of QDialog

  -> less code and more KDE standard compliant.
- some small cleanups

svn path=/trunk/kdesdk/cervisia/; revision=194360
parent 09250f1e
......@@ -18,10 +18,8 @@
#include <qcombobox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <kapplication.h>
#include <kbuttonbox.h>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
......@@ -31,106 +29,100 @@
TagDialog::TagDialog(ActionType action, const QString &sbox, const QString &repo,
QWidget *parent, const char *name)
: QDialog(parent, name, true), branchtag_button(0), forcetag_button(0)
: KDialogBase(parent, name, true, QString::null,
Ok | Cancel | Help, Ok, true),
act(action),
sandbox(sbox),
repository(repo),
branchtag_button(0),
forcetag_button(0)
{
setCaption( (action==Delete)? i18n("CVS Delete Tag") : i18n("CVS Tag") );
QBoxLayout *layout = new QVBoxLayout(this, 10);
QFrame* mainWidget = makeMainWidget();
QBoxLayout *layout = new QVBoxLayout(mainWidget, 0, spacingHint());
if (action == Delete)
{
tag_combo = new QComboBox(true, this);
tag_combo = new QComboBox(true, mainWidget);
tag_combo->setFocus();
QFontMetrics fm(fontMetrics());
tag_combo->setMinimumSize(fm.width("0")*30, tag_combo->sizeHint().height());
tag_combo->setMinimumWidth(fontMetrics().width('0') * 30);
QLabel *tag_label = new QLabel(tag_combo, i18n("&Name of tag:"), this);
QLabel *tag_label = new QLabel(tag_combo, i18n("&Name of tag:"), mainWidget);
QPushButton *tag_button = new QPushButton(i18n("Fetch &List"), this);
tag_button->setMinimumWidth(tag_button->sizeHint().width());
QPushButton *tag_button = new QPushButton(i18n("Fetch &List"), mainWidget);
connect( tag_button, SIGNAL(clicked()),
this, SLOT(tagButtonClicked()) );
QBoxLayout *tagedit_layout = new QHBoxLayout();
layout->addLayout(tagedit_layout);
QBoxLayout *tagedit_layout = new QHBoxLayout(layout);
tagedit_layout->addWidget(tag_label);
tagedit_layout->addWidget(tag_combo);
tagedit_layout->addWidget(tag_button);
}
else
{
tag_edit = new KLineEdit(this);
tag_edit = new QLineEdit(mainWidget);
tag_edit->setFocus();
QFontMetrics fm(fontMetrics());
tag_edit->setMinimumSize(fm.width("0")*30, tag_edit->sizeHint().height());
tag_edit->setMinimumWidth(fontMetrics().width('0') * 30);
QLabel *tag_label = new QLabel(tag_edit, i18n("&Name of tag:"), this);
QLabel *tag_label = new QLabel(tag_edit, i18n("&Name of tag:"), mainWidget);
QBoxLayout *tagedit_layout = new QHBoxLayout();
layout->addLayout(tagedit_layout);
QBoxLayout *tagedit_layout = new QHBoxLayout(layout);
tagedit_layout->addWidget(tag_label);
tagedit_layout->addWidget(tag_edit);
branchtag_button = new QCheckBox(i18n("Create &branch with this tag"), this);
branchtag_button = new QCheckBox(i18n("Create &branch with this tag"), mainWidget);
layout->addWidget(branchtag_button);
forcetag_button = new QCheckBox(i18n("&Force tag creation even if tag already exists"), this);
forcetag_button = new QCheckBox(i18n("&Force tag creation even if tag already exists"), mainWidget);
layout->addWidget(forcetag_button);
}
QFrame *frame = new QFrame(this);
frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
layout->addWidget(frame, 0);
KButtonBox *buttonbox = new KButtonBox(this);
QPushButton *helpbutton = buttonbox->addButton(i18n("&Help"));
helpbutton->setAutoDefault(false);
buttonbox->addStretch();
QPushButton *okbutton = buttonbox->addButton(i18n("OK"));
QPushButton *cancelbutton = buttonbox->addButton(i18n("Cancel"));
okbutton->setDefault(true);
connect( helpbutton, SIGNAL(clicked()), SLOT(helpClicked()) );
connect( okbutton, SIGNAL(clicked()), SLOT(accept()) );
connect( cancelbutton, SIGNAL(clicked()), SLOT(reject()) );
buttonbox->layout();
layout->addWidget(buttonbox, 0);
layout->activate();
resize(sizeHint());
act = action;
sandbox = sbox;
repository = repo;
setHelp("taggingbranching");
}
void TagDialog::done(int r)
bool TagDialog::branchTag() const
{
if (r == Accepted)
{
QString str = tag();
if (str.length() == 0)
{
KMessageBox::sorry(this,
i18n("You must define a tag name."),
"Cervisia");
return;
}
if (!isValidTag(str))
{
KMessageBox::sorry(this,
i18n("Tag must start with a letter and may contain "
"letters, digits and the characters '-' and '_'."),
"Cervisia");
return;
}
}
QDialog::done(r);
return branchtag_button && branchtag_button->isChecked();
}
bool TagDialog::forceTag() const
{
return forcetag_button && forcetag_button->isChecked();
}
QString TagDialog::tag() const
{
return act==Delete? tag_combo->currentText() : tag_edit->text();
}
void TagDialog::slotOk()
{
QString const str(tag());
if (str.isEmpty())
{
KMessageBox::sorry(this,
i18n("You must define a tag name."),
"Cervisia");
return;
}
if (!isValidTag(str))
{
KMessageBox::sorry(this,
i18n("Tag must start with a letter and may contain "
"letters, digits and the characters '-' and '_'."),
"Cervisia");
return;
}
KDialogBase::slotOk();
}
......@@ -149,34 +141,27 @@ void TagDialog::tagButtonClicked()
while (l.getOneLine(&str))
{
int pos1, pos2, pos3;
if (str.length() < 1 || str[0] != '\t')
if (str.isEmpty() || str[0] != '\t')
continue;
if ((pos1 = str.find(' ', 2)) == -1)
if ((pos1 = str.find(' ', 2)) < 0)
continue;
if ((pos2 = str.find('(', pos1+1)) == -1)
if ((pos2 = str.find('(', pos1 + 1)) < 0)
continue;
if ((pos3 = str.find(':', pos2+1)) == -1)
if ((pos3 = str.find(':', pos2 + 1)) < 0)
continue;
QString tag = str.mid(1, pos1-1);
QString type = str.mid(pos2+1, pos3-pos2-1);
QString const tag(str.mid(1, pos1 - 1));
QString const type(str.mid(pos2 + 1, pos3 - pos2 - 1));
if (type == QString::fromLatin1("revision") && !tags.contains(tag))
tags.append(tag);
}
tag_combo->clear();
tags.sort();
QStringList::ConstIterator it;
for (it = tags.begin(); it != tags.end(); ++it)
tag_combo->insertItem(*it);
tag_combo->clear();
tag_combo->insertStringList(tags);
}
void TagDialog::helpClicked()
{
kapp->invokeHelp("taggingbranching", "cervisia");
}
#include "tagdlg.moc"
......
......@@ -15,13 +15,16 @@
#ifndef TAGDLG_H
#define TAGDLG_H
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qdialog.h>
#include <klineedit.h>
#include <kdialogbase.h>
class TagDialog : public QDialog
class QCheckBox;
class QComboBox;
class QLineEdit;
class TagDialog : public KDialogBase
{
Q_OBJECT
......@@ -30,21 +33,17 @@ public:
TagDialog( ActionType action, const QString &sbox, const QString &repo,
QWidget *parent=0, const char *name=0 );
bool branchTag() const
{ return branchtag_button && branchtag_button->isChecked(); }
bool forceTag() const
{ return forcetag_button && forcetag_button->isChecked(); }
QString tag() const
{ return act==Delete? tag_combo->currentText() : tag_edit->text(); }
bool branchTag() const;
bool forceTag() const;
QString tag() const;
protected:
virtual void done(int r);
virtual void slotOk();
private slots:
void tagButtonClicked();
void helpClicked();
private:
ActionType act;
QString sandbox, repository;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment