~ubuntu-branches/ubuntu/saucy/kate/saucy

« back to all changes in this revision

Viewing changes to kate/plugins/katebuild-plugin/targets.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Rohan Garg, Jonathan Riddell
  • Date: 2013-06-21 00:48:29 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20130621004829-y2ui02eg0j47h94y
Tags: 4:4.10.80-0ubuntu1
[ Rohan Garg ]
* New upstream release
  - Update and sort install files
  - Drop kubuntu_pate_find_python.diff, kubuntu_kate_initial_preference.patch,
    kubuntu_find_python.diff from debian/patches , not required

[ Jonathan Riddell ]
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// Description: Widget for configuring build targets
3
 
//
4
 
// Copyright (c) 2011 Kåre Särs <kare.sars@iki.fi>
5
 
//
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.
9
 
//
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.
14
 
//
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.
19
 
 
20
 
#include "targets.h"
21
 
#include "targets.moc"
22
 
#include <klocale.h>
23
 
#include <kdebug.h>
24
 
#include <QApplication>
25
 
 
26
 
TargetsUi::TargetsUi(QWidget *parent):
27
 
QWidget(parent)
28
 
{
29
 
    targetCombo = new KComboBox(this);
30
 
    targetCombo->setEditable(true);
31
 
    targetCombo->setInsertPolicy(QComboBox::InsertAtCurrent);
32
 
    connect(targetCombo, SIGNAL(editTextChanged(QString)), this, SLOT(editTarget(QString)));
33
 
    
34
 
    newTarget = new QToolButton(this);
35
 
    newTarget->setToolTip(i18n("New"));
36
 
    newTarget->setIcon(KIcon("document-new"));
37
 
    
38
 
    copyTarget = new QToolButton(this);
39
 
    copyTarget->setToolTip(i18n("Copy"));
40
 
    copyTarget->setIcon(KIcon("edit-copy"));
41
 
 
42
 
    deleteTarget = new QToolButton(this);
43
 
    deleteTarget->setToolTip(i18n("Delete"));
44
 
    deleteTarget->setIcon(KIcon("edit-delete"));
45
 
 
46
 
    line = new QFrame(this);
47
 
    line->setFrameShadow(QFrame::Sunken);
48
 
 
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"));
55
 
 
56
 
    buildLabel = new QLabel(i18n("Build"), this);
57
 
    buildCmd = new KLineEdit(this);
58
 
    buildCmd->setClearButtonShown(true);
59
 
 
60
 
    cleanLabel = new QLabel(i18n("Clean"), this);
61
 
    cleanCmd = new KLineEdit(this);
62
 
    cleanCmd->setClearButtonShown(true);
63
 
 
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);
68
 
 
69
 
    dirLabel->setBuddy(buildDir);
70
 
    buildLabel->setBuddy(buildCmd);
71
 
    cleanLabel->setBuddy(cleanCmd);
72
 
    quickLabel->setBuddy(quickCmd);
73
 
 
74
 
    // calculate the approximate height to exceed before going to "Side Layout"
75
 
    setSideLayout();
76
 
    m_widgetsHeight = sizeHint().height();
77
 
    delete layout();
78
 
 
79
 
    setBottomLayout();
80
 
    m_useBottomLayout = true;
81
 
}
82
 
 
83
 
void TargetsUi::resizeEvent(QResizeEvent *)
84
 
{
85
 
    // check if the widgets fit in a VBox layout
86
 
    if (m_useBottomLayout && (size().height() > m_widgetsHeight) && (size().width() < m_widgetsHeight * 2.5))
87
 
    {
88
 
        delete layout();
89
 
        setSideLayout();
90
 
        m_useBottomLayout = false;
91
 
    }
92
 
    else if (!m_useBottomLayout && ((size().height() < m_widgetsHeight) || (size().width() > m_widgetsHeight * 2.5)))
93
 
    {
94
 
        delete layout();
95
 
        setBottomLayout();
96
 
        m_useBottomLayout = true;
97
 
    }
98
 
}
99
 
 
100
 
void TargetsUi::setSideLayout()
101
 
{
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);
109
 
 
110
 
    layout->addLayout(tLayout, 0, 0, 1, 4);
111
 
 
112
 
    line->setFrameShape(QFrame::HLine);
113
 
    layout->addWidget(line, 1, 0, 1, 4);
114
 
    
115
 
    layout->addWidget(dirLabel, 2, 0, Qt::AlignLeft);
116
 
    layout->addWidget(buildDir, 3, 0, 1, 3);
117
 
    layout->addWidget(browse, 3, 3);
118
 
    
119
 
    layout->addWidget(buildLabel, 4, 0, Qt::AlignLeft);
120
 
    layout->addWidget(buildCmd, 5, 0, 1, 4);
121
 
    
122
 
    layout->addWidget(cleanLabel, 6, 0, Qt::AlignLeft);
123
 
    layout->addWidget(cleanCmd, 7, 0, 1, 4);
124
 
    
125
 
    layout->addWidget(quickLabel, 8, 0, Qt::AlignLeft);
126
 
    layout->addWidget(quickCmd, 9, 0, 1, 4);
127
 
    
128
 
    layout->addItem(new QSpacerItem(1, 1), 10, 0);
129
 
    layout->setColumnStretch(0, 1);
130
 
    layout->setRowStretch(12, 1);
131
 
}
132
 
 
133
 
void TargetsUi::setBottomLayout()
134
 
{
135
 
    QGridLayout* layout = new QGridLayout(this);
136
 
    layout->addWidget(targetCombo, 0, 0);
137
 
    
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);
143
 
    
144
 
    layout->addLayout(tLayout, 1, 0);
145
 
    
146
 
    line->setFrameShape(QFrame::VLine);
147
 
    layout->addWidget(line, 0, 1, 5, 1);
148
 
 
149
 
    layout->addWidget(dirLabel, 0, 2, Qt::AlignRight);
150
 
    layout->addWidget(buildDir, 0, 3, 1, 2);
151
 
    layout->addWidget(browse, 0, 5);
152
 
    
153
 
    layout->addWidget(buildLabel, 1, 2, Qt::AlignRight);
154
 
    layout->addWidget(buildCmd, 1, 3, 1, 3);
155
 
    
156
 
    layout->addWidget(cleanLabel, 2, 2, Qt::AlignRight);
157
 
    layout->addWidget(cleanCmd, 2, 3, 1, 3);
158
 
    
159
 
    layout->addWidget(quickLabel, 3, 2, Qt::AlignRight);
160
 
    layout->addWidget(quickCmd, 3, 3, 1, 3);
161
 
    
162
 
    layout->addItem(new QSpacerItem(1, 1), 4, 0 );
163
 
    layout->setColumnStretch(3, 1);
164
 
    layout->setRowStretch(5, 1);
165
 
}
166
 
 
167
 
void TargetsUi::editTarget(const QString &text)
168
 
{
169
 
    int curPos = targetCombo->lineEdit()->cursorPosition();
170
 
    targetCombo->setItemText(targetCombo->currentIndex(), text);
171
 
    targetCombo->lineEdit()->setCursorPosition(curPos);
172
 
}
173