1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/******************************************************************************
* Copyright (C) 2010 by Johannes Steffen <johannes.steffen@st.ovgu.de> *
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "tagdialog.h"
#include "gitwrapper.h"
#include <kcombobox.h>
#include <klineedit.h>
#include <klocale.h>
#include <ktextedit.h>
#include <QCheckBox>
#include <QGroupBox>
#include <QPushButton>
#include <QTextCodec>
#include <QVBoxLayout>
#include <QLabel>
#include <QVBoxLayout>
TagDialog::TagDialog (QWidget* parent ):
KDialog (parent, Qt::Dialog),
m_localCodec(QTextCodec::codecForLocale())
{
this->setCaption(xi18nc("@title:window", "<application>Git</application> Create Tag"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Create Tag"));
QWidget* boxWidget = new QWidget(this);
QVBoxLayout* boxLayout = new QVBoxLayout(boxWidget);
this->setMainWidget(boxWidget);
QGroupBox* tagInformationGroupBox = new QGroupBox(boxWidget);
boxLayout->addWidget(tagInformationGroupBox);
tagInformationGroupBox->setTitle(i18nc("@title:group", "Tag Information"));
QVBoxLayout * tagInformationLayout = new QVBoxLayout(tagInformationGroupBox);
tagInformationGroupBox->setLayout(tagInformationLayout);
QLabel* nameLabel = new QLabel(i18nc("@label:textbox", "Tag Name:"), tagInformationGroupBox);
tagInformationLayout->addWidget(nameLabel);
m_tagNameTextEdit = new KLineEdit(tagInformationGroupBox);
tagInformationLayout->addWidget(m_tagNameTextEdit);
setOkButtonState();
connect(m_tagNameTextEdit, SIGNAL(textChanged(QString)), this, SLOT(setOkButtonState()));
QLabel* messageLabel = new QLabel(i18nc("@label:textbox", "Tag Message:"), tagInformationGroupBox);
tagInformationLayout->addWidget(messageLabel);
m_tagMessageTextEdit = new KTextEdit(tagInformationGroupBox);
m_tagMessageTextEdit->setLineWrapMode(QTextEdit::FixedColumnWidth);
m_tagMessageTextEdit->setLineWrapColumnOrWidth(72);
tagInformationLayout->addWidget(m_tagMessageTextEdit);
QGroupBox* attachToGroupBox = new QGroupBox(boxWidget);
boxLayout->addWidget(attachToGroupBox);
attachToGroupBox->setTitle(i18nc("@title:group", "Attach to"));
QHBoxLayout* attachToLayout = new QHBoxLayout();
attachToGroupBox->setLayout(attachToLayout);
QLabel* branchLabel = new QLabel(i18nc("@label:listbox", "Branch:"), attachToGroupBox);
attachToLayout->addWidget(branchLabel);
m_branchComboBox = new KComboBox(false, attachToGroupBox);
attachToLayout->addWidget(m_branchComboBox);
attachToLayout->addStretch();
this->setInitialSize(QSize(300,200));
//initialize alternate color scheme for errors
m_errorColors = m_tagNameTextEdit->palette();
m_errorColors.setColor(QPalette::Normal, QPalette::Base, Qt::red);
m_errorColors.setColor(QPalette::Inactive, QPalette::Base, Qt::red);
//get branch & tag names
GitWrapper * gitWrapper = GitWrapper::instance();
int currentIndex;
const QStringList branches = gitWrapper->branches(¤tIndex);
m_branchComboBox->addItems(branches);
m_branchComboBox->setCurrentIndex(currentIndex);
gitWrapper->tagSet(m_tagNames);
}
QByteArray TagDialog::tagMessage() const
{
return m_localCodec->fromUnicode(m_tagMessageTextEdit->toPlainText());
}
QString TagDialog::tagName() const
{
return m_tagNameTextEdit->text().trimmed();
}
QString TagDialog::baseBranch() const
{
return m_branchComboBox->currentText();
}
void TagDialog::setOkButtonState()
{
const QString tagName = m_tagNameTextEdit->text().trimmed();
QString toolTip;
if (tagName.isEmpty()) {
toolTip = i18nc("@info:tooltip", "You must enter a tag name first.");
}
else if (tagName.contains(QRegExp("\\s"))) {
toolTip = i18nc("@info:tooltip", "Tag names may not contain any whitespace.");
}
else if (m_tagNames.contains(tagName)) {
toolTip = i18nc("@info:tooltip", "A tag named '%1' already exists.", tagName);
}
this->enableButtonOk(toolTip.isEmpty());
setLineEditErrorModeActive(!toolTip.isEmpty());
m_tagNameTextEdit->setToolTip(toolTip);
this->setButtonToolTip(KDialog::Ok, toolTip);
}
void TagDialog::setLineEditErrorModeActive(bool active)
{
m_tagNameTextEdit->setPalette(active ? m_errorColors : QPalette());
}
#include "tagdialog.moc"
|