2
// Description: Widget for configuring build targets
4
// Copyright (c) 2011 Kåre Särs <kare.sars@iki.fi>
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Library General Public
8
// License version 2 as published by the Free Software Foundation.
10
// This library 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 GNU
13
// Library General Public License for more details.
15
// You should have received a copy of the GNU Library General Public License
16
// along with this library; see the file COPYING.LIB. If not, write to
17
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
// Boston, MA 02110-1301, USA.
21
#include "targets.moc"
24
#include <QApplication>
26
TargetsUi::TargetsUi(QWidget *parent):
29
targetCombo = new KComboBox(this);
30
targetCombo->setEditable(true);
31
targetCombo->setInsertPolicy(QComboBox::InsertAtCurrent);
32
connect(targetCombo, SIGNAL(editTextChanged(QString)), this, SLOT(editTarget(QString)));
34
newTarget = new QToolButton(this);
35
newTarget->setToolTip(i18n("New"));
36
newTarget->setIcon(KIcon("document-new"));
38
copyTarget = new QToolButton(this);
39
copyTarget->setToolTip(i18n("Copy"));
40
copyTarget->setIcon(KIcon("edit-copy"));
42
deleteTarget = new QToolButton(this);
43
deleteTarget->setToolTip(i18n("Delete"));
44
deleteTarget->setIcon(KIcon("edit-delete"));
46
line = new QFrame(this);
47
line->setFrameShadow(QFrame::Sunken);
49
dirLabel = new QLabel(i18n("Working directory"), this);
50
buildDir = new KLineEdit(this);
51
buildDir->setToolTip(i18n("Leave empty to use the directory of the current document. "));
52
buildDir->setClearButtonShown(true);
53
browse = new QToolButton(this);
54
browse->setIcon(KIcon("inode-directory"));
56
buildLabel = new QLabel(i18n("Build"), this);
57
buildCmd = new KLineEdit(this);
58
buildCmd->setClearButtonShown(true);
60
cleanLabel = new QLabel(i18n("Clean"), this);
61
cleanCmd = new KLineEdit(this);
62
cleanCmd->setClearButtonShown(true);
64
quickLabel = new QLabel(i18n("Quick compile"), this);
65
quickCmd = new KLineEdit(this);
66
quickCmd->setToolTip(i18n("Use:\n\"%f\" for current file\n\"%d\" for directory of current file\n\"%n\" for current file name without suffix"));
67
quickCmd->setClearButtonShown(true);
69
dirLabel->setBuddy(buildDir);
70
buildLabel->setBuddy(buildCmd);
71
cleanLabel->setBuddy(cleanCmd);
72
quickLabel->setBuddy(quickCmd);
74
// calculate the approximate height to exceed before going to "Side Layout"
76
m_widgetsHeight = sizeHint().height();
80
m_useBottomLayout = true;
83
void TargetsUi::resizeEvent(QResizeEvent *)
85
// check if the widgets fit in a VBox layout
86
if (m_useBottomLayout && (size().height() > m_widgetsHeight) && (size().width() < m_widgetsHeight * 2.5))
90
m_useBottomLayout = false;
92
else if (!m_useBottomLayout && ((size().height() < m_widgetsHeight) || (size().width() > m_widgetsHeight * 2.5)))
96
m_useBottomLayout = true;
100
void TargetsUi::setSideLayout()
102
QGridLayout* layout = new QGridLayout(this);
103
QHBoxLayout* tLayout = new QHBoxLayout();
104
tLayout->addWidget(targetCombo, 1);
105
tLayout->addWidget(newTarget, 0);
106
tLayout->addWidget(copyTarget, 0);
107
tLayout->addWidget(deleteTarget, 0);
108
tLayout->setContentsMargins(0,0,0,0);
110
layout->addLayout(tLayout, 0, 0, 1, 4);
112
line->setFrameShape(QFrame::HLine);
113
layout->addWidget(line, 1, 0, 1, 4);
115
layout->addWidget(dirLabel, 2, 0, Qt::AlignLeft);
116
layout->addWidget(buildDir, 3, 0, 1, 3);
117
layout->addWidget(browse, 3, 3);
119
layout->addWidget(buildLabel, 4, 0, Qt::AlignLeft);
120
layout->addWidget(buildCmd, 5, 0, 1, 4);
122
layout->addWidget(cleanLabel, 6, 0, Qt::AlignLeft);
123
layout->addWidget(cleanCmd, 7, 0, 1, 4);
125
layout->addWidget(quickLabel, 8, 0, Qt::AlignLeft);
126
layout->addWidget(quickCmd, 9, 0, 1, 4);
128
layout->addItem(new QSpacerItem(1, 1), 10, 0);
129
layout->setColumnStretch(0, 1);
130
layout->setRowStretch(12, 1);
133
void TargetsUi::setBottomLayout()
135
QGridLayout* layout = new QGridLayout(this);
136
layout->addWidget(targetCombo, 0, 0);
138
QHBoxLayout* tLayout = new QHBoxLayout();
139
tLayout->addWidget(newTarget, 0);
140
tLayout->addWidget(copyTarget, 0);
141
tLayout->addWidget(deleteTarget, 0);
142
tLayout->setContentsMargins(0,0,0,0);
144
layout->addLayout(tLayout, 1, 0);
146
line->setFrameShape(QFrame::VLine);
147
layout->addWidget(line, 0, 1, 5, 1);
149
layout->addWidget(dirLabel, 0, 2, Qt::AlignRight);
150
layout->addWidget(buildDir, 0, 3, 1, 2);
151
layout->addWidget(browse, 0, 5);
153
layout->addWidget(buildLabel, 1, 2, Qt::AlignRight);
154
layout->addWidget(buildCmd, 1, 3, 1, 3);
156
layout->addWidget(cleanLabel, 2, 2, Qt::AlignRight);
157
layout->addWidget(cleanCmd, 2, 3, 1, 3);
159
layout->addWidget(quickLabel, 3, 2, Qt::AlignRight);
160
layout->addWidget(quickCmd, 3, 3, 1, 3);
162
layout->addItem(new QSpacerItem(1, 1), 4, 0 );
163
layout->setColumnStretch(3, 1);
164
layout->setRowStretch(5, 1);
167
void TargetsUi::editTarget(const QString &text)
169
int curPos = targetCombo->lineEdit()->cursorPosition();
170
targetCombo->setItemText(targetCombo->currentIndex(), text);
171
targetCombo->lineEdit()->setCursorPosition(curPos);