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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/***************************************************************************
* Copyright (C) 2003 by S�astien Laot *
* slaout@linux62.org *
* *
* 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 <kicondialog.h>
#include <tqlineedit.h>
#include <kiconview.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <klocale.h>
#include <kglobalsettings.h>
#include <kpushbutton.h>
#include <kguiitem.h>
#include <kmessagebox.h>
#include <tqsize.h>
#include <tqpainter.h>
#include <kapplication.h>
#include <kiconloader.h>
#include <kmainwindow.h>
#include "newbasketdialog.h"
#include "basketfactory.h"
#include "basket.h"
#include "basketlistview.h"
#include "variouswidgets.h"
#include "kcolorcombo2.h"
#include "tools.h"
#include "global.h"
#include "bnpview.h"
/** class SingleSelectionKIconView: */
SingleSelectionKIconView::SingleSelectionKIconView(TQWidget *tqparent, const char *name, WFlags f)
: KIconView(tqparent, name, f), m_lastSelected(0)
{
connect( this, TQT_SIGNAL(selectionChanged(TQIconViewItem*)), this, TQT_SLOT(slotSelectionChanged(TQIconViewItem*)) );
connect( this, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged()) );
}
TQDragObject* SingleSelectionKIconView::dragObject()
{
return 0;
}
void SingleSelectionKIconView::slotSelectionChanged(TQIconViewItem *item)
{
if (item)
m_lastSelected = item;
}
void SingleSelectionKIconView::slotSelectionChanged()
{
if (m_lastSelected && !m_lastSelected->isSelected())
m_lastSelected->setSelected(true);
}
/** class NewBasketDefaultProperties: */
NewBasketDefaultProperties::NewBasketDefaultProperties()
: icon("")
, backgroundImage("")
, backgroundColor()
, textColor()
, freeLayout(false)
, columnCount(1)
{
}
/** class NewBasketDialog: */
NewBasketDialog::NewBasketDialog(Basket *tqparentBasket, const NewBasketDefaultProperties &defaultProperties, TQWidget *tqparent)
: KDialogBase(KDialogBase::Swallow, i18n("New Basket"), KDialogBase::Ok | KDialogBase::Cancel,
KDialogBase::Ok, tqparent, /*name=*/"NewBasket", /*modal=*/true, /*separator=*/true)
, m_defaultProperties(defaultProperties)
{
TQWidget *page = new TQWidget(this);
TQVBoxLayout *topLayout = new TQVBoxLayout(page, /*margin=*/0, spacingHint());
// Icon, Name and Background Color:
TQHBoxLayout *nameLayout = new TQHBoxLayout(0, marginHint()*2/3, spacingHint());
m_icon = new KIconButton(page);
m_icon->setIconType(KIcon::NoGroup, KIcon::Action);
m_icon->setIconSize(16);
m_icon->setIcon(m_defaultProperties.icon.isEmpty() ? "basket" : m_defaultProperties.icon);
int size = TQMAX(m_icon->tqsizeHint().width(), m_icon->tqsizeHint().height());
m_icon->setFixedSize(size, size); // Make it square!
TQToolTip::add(m_icon, i18n("Icon"));
m_name = new TQLineEdit(/*i18n("Basket"), */page);
m_name->setMinimumWidth(m_name->fontMetrics().maxWidth()*20);
connect( m_name, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(nameChanged(const TQString&)) );
enableButtonOK(false);
TQToolTip::add(m_name, i18n("Name"));
m_backgroundColor = new KColorCombo2(TQColor(), KGlobalSettings::baseColor(), page);
m_backgroundColor->setColor(TQColor());
m_backgroundColor->setFixedSize(m_backgroundColor->tqsizeHint());
m_backgroundColor->setColor(m_defaultProperties.backgroundColor);
TQToolTip::add(m_backgroundColor, i18n("Background color"));
nameLayout->addWidget(m_icon);
nameLayout->addWidget(m_name);
nameLayout->addWidget(m_backgroundColor);
topLayout->addLayout(nameLayout);
TQHBoxLayout *tqlayout = new TQHBoxLayout(/*tqparent=*/0, /*margin=*/0, spacingHint());
KPushButton *button = new KPushButton( KGuiItem(i18n("&Manage Templates..."), "configure"), page );
connect( button, TQT_SIGNAL(clicked()), this, TQT_SLOT(manageTemplates()) );
button->hide();
// Compute the right template to use as the default:
TQString defaultTemplate = "free";
if (!m_defaultProperties.freeLayout) {
if (m_defaultProperties.columnCount == 1)
defaultTemplate = "1column";
else if (m_defaultProperties.columnCount == 2)
defaultTemplate = "2columns";
else
defaultTemplate = "3columns";
}
// Empty:
// * * * * *
// Personnal:
// *To Do
// Professionnal:
// *Meeting Summary
// Hobbies:
// *
m_templates = new SingleSelectionKIconView(page);
m_templates->setItemsMovable(false);
m_templates->setMode(KIconView::Select);
m_templates->setGridX(m_templates->maxItemWidth());
KIconViewItem *lastTemplate = 0;
TQPixmap icon(40, 53);
TQPainter painter(&icon);
painter.fillRect(0, 0, icon.width(), icon.height(), KGlobalSettings::baseColor());
painter.setPen(KGlobalSettings::textColor());
painter.drawRect(0, 0, icon.width(), icon.height());
painter.end();
lastTemplate = new KIconViewItem(m_templates, lastTemplate, i18n("One column"), icon);
if (defaultTemplate == "1column")
m_templates->setSelected(lastTemplate, true);
painter.begin(&icon);
painter.fillRect(0, 0, icon.width(), icon.height(), KGlobalSettings::baseColor());
painter.setPen(KGlobalSettings::textColor());
painter.drawRect(0, 0, icon.width(), icon.height());
painter.drawLine(icon.width() / 2, 0, icon.width() / 2, icon.height());
painter.end();
lastTemplate = new KIconViewItem(m_templates, lastTemplate, i18n("Two columns"), icon);
if (defaultTemplate == "2columns")
m_templates->setSelected(lastTemplate, true);
painter.begin(&icon);
painter.fillRect(0, 0, icon.width(), icon.height(), KGlobalSettings::baseColor());
painter.setPen(KGlobalSettings::textColor());
painter.drawRect(0, 0, icon.width(), icon.height());
painter.drawLine(icon.width() / 3, 0, icon.width() / 3, icon.height());
painter.drawLine(icon.width() * 2 / 3, 0, icon.width() * 2 / 3, icon.height());
painter.end();
lastTemplate = new KIconViewItem(m_templates, lastTemplate, i18n("Three columns"), icon);
if (defaultTemplate == "3columns")
m_templates->setSelected(lastTemplate, true);
painter.begin(&icon);
painter.fillRect(0, 0, icon.width(), icon.height(), KGlobalSettings::baseColor());
painter.setPen(KGlobalSettings::textColor());
painter.drawRect(0, 0, icon.width(), icon.height());
painter.drawRect(icon.width() / 5, icon.width() / 5, icon.width() / 4, icon.height() / 8);
painter.drawRect(icon.width() * 2 / 5, icon.width() * 2 / 5, icon.width() / 4, icon.height() / 8);
painter.end();
lastTemplate = new KIconViewItem(m_templates, lastTemplate, i18n("Free"), icon);
if (defaultTemplate == "free")
m_templates->setSelected(lastTemplate, true);
/* painter.begin(&icon);
painter.fillRect(0, 0, icon.width(), icon.height(), KGlobalSettings::baseColor());
painter.setPen(KGlobalSettings::textColor());
painter.drawRect(0, 0, icon.width(), icon.height());
painter.drawRect(icon.width() * 2 / 5, icon.height() * 3 / 7, icon.width() / 5, icon.height() / 7);
painter.end();
lastTemplate = new KIconViewItem(m_templates, lastTemplate, i18n("Mind map"), icon);*/
m_templates->setMinimumHeight(topLayout->tqminimumSize().width() * 9 / 16);
TQLabel *label = new TQLabel(m_templates, i18n("&Template:"), page);
tqlayout->addWidget(label, /*stretch=*/0, TQt::AlignBottom);
tqlayout->addStretch();
tqlayout->addWidget(button, /*stretch=*/0, TQt::AlignBottom);
topLayout->addLayout(tqlayout);
topLayout->addWidget(m_templates);
tqlayout = new TQHBoxLayout(/*tqparent=*/0, /*margin=*/0, spacingHint());
m_createIn = new TQComboBox(page);
m_createIn->insertItem(i18n("(Baskets)"));
label = new TQLabel(m_createIn, i18n("C&reate in:"), page);
HelpLabel *helpLabel = new HelpLabel(i18n("How is it useful?"), i18n(
"<p>Creating baskets inside of other baskets to form a hierarchy allows you to be more organized by eg.:</p><ul>"
"<li>Grouping baskets by themes or topics;</li>"
"<li>Grouping baskets in folders for different projects;</li>"
"<li>Making sections with sub-baskets representing chapters or pages;</li>"
"<li>Making a group of baskets to export together (to eg. email them to people).</li></ul>"), page);
tqlayout->addWidget(label);
tqlayout->addWidget(m_createIn);
tqlayout->addWidget(helpLabel);
tqlayout->addStretch();
topLayout->addLayout(tqlayout);
m_basketsMap.clear();
m_basketsMap.insert(/*index=*/0, /*basket=*/0L);
populateBasketsList(Global::bnpView->firstListViewItem(), /*indent=*/1, /*index=*/1);
connect( m_templates, TQT_SIGNAL(doubleClicked(TQIconViewItem*)), this, TQT_SLOT(slotOk()) );
connect( m_templates, TQT_SIGNAL(returnPressed(TQIconViewItem*)), this, TQT_SLOT(returnPressed()) );
if (tqparentBasket) {
int index = 0;
for (TQMap<int, Basket*>::Iterator it = m_basketsMap.begin(); it != m_basketsMap.end(); ++it)
if (it.data() == tqparentBasket) {
index = it.key();
break;
}
if (index <= 0)
return;
if (m_createIn->currentItem() != index)
m_createIn->setCurrentItem(index);
}
setMainWidget(page);
}
void NewBasketDialog::returnPressed()
{
actionButton(KDialogBase::Ok)->animateClick();
}
int NewBasketDialog::populateBasketsList(TQListViewItem *item, int indent, int index)
{
static const int ICON_SIZE = 16;
while (item) {
// Get the basket data:
Basket *basket = ((BasketListViewItem*)item)->basket();
TQPixmap icon = kapp->iconLoader()->loadIcon(basket->icon(), KIcon::NoGroup, ICON_SIZE, KIcon::DefaultState, 0L, /*canReturnNull=*/false);
icon = Tools::indentPixmap(icon, indent, 2 * ICON_SIZE / 3);
// Append item to the list:
m_createIn->insertItem(icon, basket->basketName());
m_basketsMap.insert(index, basket);
++index;
// Append childs of item to the list:
index = populateBasketsList(item->firstChild(), indent + 1, index);
// Add next sibling basket:
item = item->nextSibling();
}
return index;
}
NewBasketDialog::~NewBasketDialog()
{
}
void NewBasketDialog::polish()
{
KDialogBase::polish();
m_name->setFocus();
}
void NewBasketDialog::nameChanged(const TQString &newName)
{
enableButtonOK(!newName.isEmpty());
}
void NewBasketDialog::slotOk()
{
TQIconViewItem *item = ((SingleSelectionKIconView*)m_templates)->selectedItem();
TQString templateName;
if (item->text() == i18n("One column"))
templateName = "1column";
if (item->text() == i18n("Two columns"))
templateName = "2columns";
if (item->text() == i18n("Three columns"))
templateName = "3columns";
if (item->text() == i18n("Free-form"))
templateName = "free";
if (item->text() == i18n("Mind map"))
templateName = "mindmap";
Global::bnpView->closeAllEditors();
TQString backgroundImage;
TQColor textColor;
if (m_backgroundColor->color() == m_defaultProperties.backgroundColor) {
backgroundImage = m_defaultProperties.backgroundImage;
textColor = m_defaultProperties.textColor;
}
BasketFactory::newBasket(m_icon->icon(), m_name->text(), backgroundImage, m_backgroundColor->color(), textColor, templateName, m_basketsMap[m_createIn->currentItem()]);
if(Global::mainWindow()) Global::mainWindow()->show();
KDialogBase::slotOk();
}
void NewBasketDialog::manageTemplates()
{
KMessageBox::information(this, "Wait a minute! There is no template for now: they will come with time... :-D");
}
#include "newbasketdialog.moc"
|