Ran am2cmake.
[basket4.git] / src / basketproperties.cpp
blob3de1961fc38fc593d8658679c7288543ecd550c5
1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
3 * slaout@linux62.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program 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 *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <qlineedit.h>
22 #include <qcombobox.h>
23 #include <qvbuttongroup.h>
24 //Added by qt3to4:
25 #include <Q3HBoxLayout>
26 #include <Q3GridLayout>
27 #include <QPixmap>
28 #include <Q3VBoxLayout>
29 #include <knuminput.h>
30 #include <kkeybutton.h>
31 #include <qlayout.h>
32 #include <qlabel.h>
33 #include <q3buttongroup.h>
34 #include <qradiobutton.h>
35 #include <qstringlist.h>
36 #include <klocale.h>
37 #include <qstyle.h>
38 #include <kapplication.h>
39 #include <kiconloader.h>
40 #include <kglobalsettings.h>
42 #include "kicondialog.h"
43 #include "basketproperties.h"
44 #include "basket.h"
45 #include "kcolorcombo2.h"
46 #include "variouswidgets.h"
47 #include "global.h"
48 #include "backgroundmanager.h"
50 BasketPropertiesDialog::BasketPropertiesDialog(Basket *basket, QWidget *parent)
51 : KDialogBase(KDialogBase::Swallow, i18n("Basket Properties"), KDialogBase::Ok | KDialogBase::Apply | KDialogBase::Cancel,
52 KDialogBase::Ok, parent, /*name=*/"BasketProperties", /*modal=*/true, /*separator=*/false),
53 m_basket(basket)
55 QWidget *page = new QWidget(this);
56 Q3VBoxLayout *topLayout = new Q3VBoxLayout(page, /*margin=*/0, spacingHint());
58 // Icon and Name:
59 Q3HBoxLayout *nameLayout = new Q3HBoxLayout(0, marginHint()*2/3, spacingHint());
60 m_icon = new KIconButton(page);
61 m_icon->setIconType(KIcon::NoGroup, KIcon::Action);
62 m_icon->setIconSize(16);
63 m_icon->setIcon(m_basket->icon());
64 int size = QMAX(m_icon->sizeHint().width(), m_icon->sizeHint().height());
65 m_icon->setFixedSize(size, size); // Make it square!
66 QToolTip::add(m_icon, i18n("Icon"));
67 m_name = new QLineEdit(m_basket->basketName(), page);
68 m_name->setMinimumWidth(m_name->fontMetrics().maxWidth()*20);
69 QToolTip::add(m_name, i18n("Name"));
70 nameLayout->addWidget(m_icon);
71 nameLayout->addWidget(m_name);
72 topLayout->addLayout(nameLayout);
74 // Appearance:
75 Q3GroupBox *appearance = new Q3GroupBox(1, Qt::Horizontal, i18n("Appearance"), page);
76 QWidget *appearanceWidget = new QWidget(appearance);
77 Q3GridLayout *grid = new Q3GridLayout(appearanceWidget, /*nRows=*/3, /*nCols=*/2, /*margin=*/0, spacingHint());
78 m_backgroundImage = new QComboBox(appearanceWidget);
79 m_backgroundColor = new KColorCombo2(m_basket->backgroundColorSetting(), KGlobalSettings::baseColor(), appearanceWidget);
80 m_textColor = new KColorCombo2(m_basket->textColorSetting(), KGlobalSettings::textColor(), appearanceWidget);
81 QLabel *label1 = new QLabel(m_backgroundImage, i18n("Background &image:"), appearanceWidget);
82 QLabel *label2 = new QLabel(m_backgroundColor, i18n("&Background color:"), appearanceWidget);
83 QLabel *label3 = new QLabel(m_textColor, i18n("&Text color:"), appearanceWidget);
84 grid->addWidget(label1, 0, 0, Qt::AlignVCenter);
85 grid->addWidget(label2, 1, 0, Qt::AlignVCenter);
86 grid->addWidget(label3, 2, 0, Qt::AlignVCenter);
87 grid->addWidget(m_backgroundImage, 0, 1, Qt::AlignVCenter);
88 grid->addWidget(m_backgroundColor, 1, 1, Qt::AlignVCenter);
89 grid->addWidget(m_textColor, 2, 1, Qt::AlignVCenter);
90 topLayout->addWidget(appearance);
92 m_backgroundImage->insertItem(i18n("(None)"), 0);
93 m_backgroundImagesMap.insert(0, "");
94 QStringList backgrounds = Global::backgroundManager->imageNames();
95 int index = 1;
96 for (QStringList::Iterator it = backgrounds.begin(); it != backgrounds.end(); ++it) {
97 QPixmap *preview = Global::backgroundManager->preview(*it);
98 if (preview) {
99 m_backgroundImagesMap.insert(index, *it);
100 m_backgroundImage->insertItem(*preview, index);
101 if (m_basket->backgroundImageName() == *it)
102 m_backgroundImage->setCurrentItem(index);
103 index++;
106 // m_backgroundImage->insertItem(i18n("Other..."), -1);
107 int BUTTON_MARGIN = kapp->style().pixelMetric(QStyle::PM_ButtonMargin);
108 m_backgroundImage->setSizeLimit(50/*75 * 6 / m_backgroundImage->sizeHint().height()*/);
109 m_backgroundImage->setMinimumHeight(75 + 2 * BUTTON_MARGIN);
111 // Disposition:
112 m_disposition = new Q3VButtonGroup(i18n("Disposition"), page);
113 QWidget *columnsWidget = new QWidget(m_disposition);
114 Q3HBoxLayout *dispoLayout = new Q3HBoxLayout(columnsWidget, /*margin=*/0, spacingHint());
115 QRadioButton *radio = new QRadioButton(i18n("Col&umns:"), columnsWidget);
116 m_columnCount = new KIntNumInput(m_basket->columnsCount(), columnsWidget);
117 m_columnCount->setRange(1, 20, /*step=*/1, /*slider=*/false);
118 m_columnCount->setValue(m_basket->columnsCount());
119 connect( m_columnCount, SIGNAL(valueChanged(int)), this, SLOT(selectColumnsLayout()) );
120 dispoLayout->addWidget(radio);
121 dispoLayout->addWidget(m_columnCount);
122 m_disposition->insert(radio);
123 new QRadioButton(i18n("&Free-form"), m_disposition);
124 QRadioButton *mindMap = new QRadioButton(i18n("&Mind map"), m_disposition); // TODO: "Learn more..."
125 int height = QMAX(mindMap->sizeHint().height(), m_columnCount->sizeHint().height()); // Make all radioButtons vertically equaly-spaced!
126 mindMap->setMinimumSize(mindMap->sizeHint().width(), height); // Because the m_columnCount can be heigher, and make radio1 and radio2 more spaced than radio2 and radio3.
127 m_disposition->setButton(m_basket->isFreeLayout() ? (m_basket->isMindMap() ? 2 : 1) : 0);
128 topLayout->addWidget(m_disposition);
130 mindMap->hide();
132 // Keyboard Shortcut:
133 m_shortcutRole = new Q3VButtonGroup(i18n("&Keyboard Shortcut"), page);
134 QWidget *shortcutWidget = new QWidget(m_shortcutRole);
135 Q3HBoxLayout *shortcutLayout = new Q3HBoxLayout(shortcutWidget, /*margin=*/0, spacingHint());
136 m_shortcut = new KKeyButton(shortcutWidget);
137 m_shortcut->setShortcut(m_basket->shortcut(), /*bQtShortcut=*/true);
138 HelpLabel *helpLabel = new HelpLabel(i18n("Learn some tips..."), i18n(
139 "<p><strong>Easily Remember your Shortcuts</strong>:<br>"
140 "With the first option, giving the basket a shortcut of the form <strong>Alt+Letter</strong> will underline that letter in the basket tree.<br>"
141 "For instance, if you are assigning the shortcut <i>Alt+T</i> to a basket named <i>Tips</i>, the basket will be displayed as <i><u>T</u>ips</i> in the tree. "
142 "It helps you visualize the shortcuts to remember them more quickly.</p>"
143 "<p><strong>Local vs Global</strong>:<br>"
144 "The first option allows to show the basket while the main window is active. "
145 "Global shortcuts are valid from anywhere, even if the window is hidden.</p>"
146 "<p><strong>Show vs Switch</strong>:<br>"
147 "The last option makes this basket the current one without opening the main window. "
148 "It is useful in addition to the configurable global shortcuts, eg. to paste the clipboard or the selection into the current basket from anywhere.</p>"),
149 shortcutWidget);
150 shortcutLayout->addWidget(m_shortcut);
151 shortcutLayout->addStretch();
152 shortcutLayout->addWidget(helpLabel);
153 connect( m_shortcut, SIGNAL(capturedShortcut(const KShortcut&)), this, SLOT(capturedShortcut(const KShortcut&)) );
154 new QRadioButton(i18n("S&how this basket"), m_shortcutRole);
155 new QRadioButton(i18n("Show this basket (&global shortcut)"), m_shortcutRole);
156 new QRadioButton(i18n("S&witch to this basket (global shortcut)"), m_shortcutRole);
157 m_shortcutRole->setButton(m_basket->shortcutAction()/* + 1*/); // Id 0 is the KKeyButton!
158 topLayout->addWidget(m_shortcutRole);
160 topLayout->addSpacing(marginHint());
161 topLayout->addStretch(10);
163 setMainWidget(page);
166 BasketPropertiesDialog::~BasketPropertiesDialog()
170 void BasketPropertiesDialog::polish()
172 KDialogBase::polish();
173 m_name->setFocus();
176 void BasketPropertiesDialog::applyChanges()
178 m_basket->setDisposition(m_disposition->selectedId(), m_columnCount->value());
179 m_basket->setShortcut(m_shortcut->shortcut(), m_shortcutRole->selectedId());
180 // Should be called LAST, because it will emit the propertiesChanged() signal and the tree will be able to show the newly set Alt+Letter shortcut:
181 m_basket->setAppearance(m_icon->icon(), m_name->text(), m_backgroundImagesMap[m_backgroundImage->currentItem()], m_backgroundColor->color(), m_textColor->color());
182 m_basket->save();
185 void BasketPropertiesDialog::slotApply()
187 applyChanges();
188 KDialogBase::slotApply();
191 void BasketPropertiesDialog::slotOk()
193 applyChanges();
194 KDialogBase::slotOk();
197 void BasketPropertiesDialog::capturedShortcut(const KShortcut &shortcut)
199 // TODO: Validate it!
200 m_shortcut->setShortcut(shortcut, /*bQtShortcut=*/true);
203 void BasketPropertiesDialog::selectColumnsLayout()
205 m_disposition->setButton(0);
208 #include "basketproperties.moc"