OSDN Git Service

9244a2b6926db5b80e3bbdb93df5a989bdfbefe0
[qt-creator-jp/qt-creator-jp.git] / src / tools / qtcreatorwidgets / customwidgets.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "customwidgets.h"
35
36 #include <QtGui/QMenu>
37 #include <QtGui/QAction>
38 #include <QtDesigner/QExtensionManager>
39 #include <QtDesigner/QDesignerFormEditorInterface>
40
41 static const char *groupC = "QtCreator";
42
43 NewClassCustomWidget::NewClassCustomWidget(QObject *parent) :
44    QObject(parent),
45    CustomWidget<Utils::NewClassWidget>
46        (QLatin1String("<utils/newclasswidget.h>"),
47         false,
48         QLatin1String(groupC),
49         QIcon(),
50         QLatin1String("Widget to enter classes and source files"))
51 {
52 }
53
54 ClassNameValidatingLineEdit_CW::ClassNameValidatingLineEdit_CW(QObject *parent) :
55    QObject(parent),
56    CustomWidget<Utils::ClassNameValidatingLineEdit>
57        (QLatin1String("<utils/classnamevalidatinglineedit.h>"),
58         false,
59         QLatin1String(groupC),
60         QIcon(),
61         QLatin1String("Line Edit that validates a class name"))
62 {
63 }
64
65 FileNameValidatingLineEdit_CW::FileNameValidatingLineEdit_CW(QObject *parent) :
66    QObject(parent),
67    CustomWidget<Utils::FileNameValidatingLineEdit>
68        (QLatin1String("<utils/filenamevalidatinglineedit.h>"),
69         false,
70         QLatin1String(groupC),
71         QIcon(),
72         QLatin1String("Line Edit that validates a file name"))
73 {
74 }
75
76 ProjectNameValidatingLineEdit_CW::ProjectNameValidatingLineEdit_CW(QObject *parent) :
77    QObject(parent),
78    CustomWidget<Utils::ProjectNameValidatingLineEdit>
79        (QLatin1String("<utils/projectnamevalidatinglineedit.h>"),
80         false,
81         QLatin1String(groupC),
82         QIcon(),
83         QLatin1String("Line Edit that validates a project name"))
84 {
85 }
86
87 LineColumnLabel_CW::LineColumnLabel_CW(QObject *parent) :
88    QObject(parent),
89    CustomWidget<Utils::LineColumnLabel>
90        (QLatin1String("<utils/linecolumnlabel.h>"),
91         false,
92         QLatin1String(groupC),
93         QIcon(),
94         QLatin1String("Label suited for displaying line numbers with a fixed with depending on the font size"),
95         QSize(100, 20))
96 {
97 }
98
99 PathChooser_CW::PathChooser_CW(QObject *parent) :
100    QObject(parent),
101    CustomWidget<Utils::PathChooser>
102        (QLatin1String("<utils/pathchooser.h>"),
103         false,
104         QLatin1String(groupC),
105         QIcon(),
106         QLatin1String("Input widget for paths with a browse button"))
107 {
108 }
109
110 IconButton_CW::IconButton_CW(QObject *parent) :
111     QObject(parent),
112     CustomWidget<Utils::IconButton>
113         (QLatin1String("<utils/fancylineedit.h>"),
114          false,
115          QLatin1String(groupC),
116          QIcon(),
117          QLatin1String("Icon button of FancyLineEdit"))
118 {
119 }
120
121 FancyLineEdit_CW::FancyLineEdit_CW(QObject *parent) :
122    QObject(parent),
123    CustomWidget<Utils::FancyLineEdit>
124        (QLatin1String("<utils/fancylineedit.h>"),
125         false,
126         QLatin1String(groupC),
127         QIcon(),
128         QLatin1String("A Line edit with a clickable menu pixmap"))
129 {
130 }
131
132 FilterLineEdit_CW::FilterLineEdit_CW(QObject *parent) :
133    QObject(parent),
134    CustomWidget<Utils::FilterLineEdit>
135        (QLatin1String("<utils/filterlineedit.h>"),
136         false,
137         QLatin1String(groupC),
138         QIcon(),
139         QLatin1String("A Line edit customized for filtering"))
140 {
141 }
142
143
144 QtColorButton_CW::QtColorButton_CW(QObject *parent) :
145    QObject(parent),
146    CustomWidget<Utils::QtColorButton>
147        (QLatin1String("<utils/qtcolorbutton.h>"),
148         false,
149         QLatin1String(groupC),
150         QIcon(),
151         QLatin1String("A color button that spawns a QColorDialog on click"))
152 {
153 }
154
155 QWidget *FancyLineEdit_CW::createWidget(QWidget *parent)
156 {
157     Utils::FancyLineEdit *fle = new Utils::FancyLineEdit(parent);
158     fle->setButtonVisible(Utils::FancyLineEdit::Left, true);
159     fle->setButtonPixmap(Utils::FancyLineEdit::Left,
160             fle->style()->standardIcon(QStyle::SP_ArrowRight).pixmap(16));
161     QMenu *menu = new QMenu(fle);
162     menu->addAction(QLatin1String("Example"));
163     fle->setButtonMenu(Utils::FancyLineEdit::Left, menu);
164     return fle;
165 }
166
167 SubmitEditorWidget_CW::SubmitEditorWidget_CW(QObject *parent) :
168     QObject(parent),
169     CustomWidget<Utils::SubmitEditorWidget>
170     (QLatin1String("<utils/submiteditorwidget.h>"),
171     false,
172     QLatin1String(groupC),
173     QIcon(),
174     QLatin1String("Submit editor showing message and file list"))
175 {
176 }
177
178 SubmitFieldWidget_CW::SubmitFieldWidget_CW(QObject *parent) :
179     QObject(parent),
180     CustomWidget<Utils::SubmitFieldWidget>
181     (QLatin1String("<utils/submitfieldwidget.h>"),
182     false,
183     QLatin1String(groupC),
184     QIcon(),
185     QLatin1String("Show predefined fields of a submit message in a control based on mail address controls"))
186 {
187 }
188
189 PathListEditor_CW::PathListEditor_CW(QObject *parent) :
190     QObject(parent),
191     CustomWidget<Utils::PathListEditor>
192     (QLatin1String("<utils/pathlisteditor.h>"),
193     false,
194     QLatin1String(groupC),
195     QIcon(),
196     QLatin1String("Edit a path list variable"))
197 {
198 }
199
200 DetailsButton_CW::DetailsButton_CW(QObject *parent) :
201     QObject(parent),
202     CustomWidget<Utils::DetailsButton>
203     (QLatin1String("<utils/detailsbutton.h>"),
204     false,
205     QLatin1String(groupC),
206     QIcon(),
207     QLatin1String("Expandable button for 'Details'"))
208 {
209 }
210
211 StyledBar_CW::StyledBar_CW(QObject *parent) :
212     QObject(parent),
213     CustomWidget<Utils::StyledBar>
214     (QLatin1String("<utils/styledbar.h>"),
215     false,
216     QLatin1String(groupC),
217     QIcon(),
218     QLatin1String("Styled bar"))
219 {
220 }
221
222 StyledSeparator_CW::StyledSeparator_CW(QObject *parent) :
223     QObject(parent),
224     CustomWidget<Utils::StyledSeparator>
225     (QLatin1String("<utils/styledbar.h>"),
226     false,
227     QLatin1String(groupC),
228     QIcon(),
229     QLatin1String("Styled separator"))
230 {
231 }
232
233 Wizard_CW::Wizard_CW(QObject *parent) :
234     QObject(parent),
235     CustomWidget<Utils::Wizard>
236     (QLatin1String("<utils/wizard.h>"),
237     true,
238     QLatin1String(groupC),
239     QIcon(),
240     QLatin1String("Wizard with progress indicator"))
241 {
242 }
243
244 WelcomePageWidget_CW::WelcomePageWidget_CW(QObject *parent) :
245     QObject(parent),
246     CustomWidget<Utils::WelcomeModeTreeWidget>
247         (QLatin1String("<utils/welcomemodetreewidget.h>"),
248         false,
249         QLatin1String(groupC),
250         QIcon(),
251         QLatin1String("Welcome page widget"))
252 {
253 }
254
255 QWidget *WelcomePageWidget_CW::createWidget(QWidget *parent)
256 {
257     Utils::WelcomeModeTreeWidget *rc = new Utils::WelcomeModeTreeWidget(parent);
258     rc->addNewsItem(QLatin1String("Breaking news"),
259                         QLatin1String("Bla bla bla"), QLatin1String("qt.nokia.com"));
260     rc->addNewsItem(QLatin1String("Yesterday's breaking news"),
261                         QLatin1String("Blub blub blub"), QLatin1String("qt.nokia.com"));
262     return rc;
263 }
264
265 WelcomeModeLabel_CW::WelcomeModeLabel_CW(QObject *parent) :
266     QObject(parent),
267     CustomWidget<Utils::WelcomeModeLabel>
268     (QLatin1String("<utils/welcomemodetreewidget.h>"),
269     false,
270     QLatin1String(groupC),
271     QIcon(),
272     QLatin1String("Welcome page header label"))
273 {
274 }
275
276 CrumblePath_CW::CrumblePath_CW(QObject *parent) :
277     QObject(parent),
278     CustomWidget<Utils::CrumblePath>
279     (QLatin1String("<utils/crumblepath.h>"),
280     false,
281     QLatin1String(groupC),
282     QIcon(),
283     QLatin1String("Crumble Path"))
284 {
285 };
286
287
288 DetailsWidget_CW::DetailsWidget_CW(QObject *parent) :
289     QObject(parent),
290     CustomWidget<Utils::DetailsWidget>
291     (QLatin1String("<utils/detailswidget.h>"),
292     true,
293     QLatin1String(groupC),
294     QIcon(),
295     QLatin1String("Expandable widget for 'Details'. You might need an expandable spacer below."))
296 {
297 }
298
299 QString DetailsWidget_CW::domXml() const
300 {
301     // Expanded from start, else child visibility is wrong
302     const char *xmlC ="\
303 <ui language=\"c++\" displayname=\"DetailsWidget\">\
304     <widget class=\"Utils::DetailsWidget\" name=\"detailsWidget\">\
305         <property name=\"geometry\">\
306             <rect><x>0</x><y>0</y><width>160</width><height>80</height></rect>\
307         </property>\
308         <property name=\"summaryText\">\
309             <string>Summary</string>\
310         </property>\
311         <property name=\"expanded\">\
312             <bool>true</bool>\
313         </property>\
314         <widget class=\"QWidget\" name=\"detailsContainer\" />\
315     </widget>\
316     <customwidgets>\
317         <customwidget>\
318             <class>Utils::DetailsWidget</class>\
319             <addpagemethod>setWidget</addpagemethod>\
320         </customwidget>\
321     </customwidgets>\
322 </ui>";
323     return QLatin1String(xmlC);
324 }
325
326 void DetailsWidget_CW::initialize(QDesignerFormEditorInterface *core)
327 {
328     const bool firstTime = !initialized();
329     CustomWidget<Utils::DetailsWidget>::initialize(core);
330     if (firstTime)
331         if (QExtensionManager *manager = core->extensionManager())
332             manager->registerExtensions(new DetailsWidgetExtensionFactory(manager), Q_TYPEID(QDesignerContainerExtension));
333 }
334
335 DetailsWidgetContainerExtension::DetailsWidgetContainerExtension(Utils::DetailsWidget *widget, QObject *parent) :
336     QObject(parent),
337     m_detailsWidget(widget)
338 {
339 }
340
341 void DetailsWidgetContainerExtension::addWidget(QWidget *widget)
342 {
343     if (m_detailsWidget->widget()) {
344         qWarning("Cannot add 2nd child to DetailsWidget");
345     } else {
346         m_detailsWidget->setWidget(widget);
347     }
348 }
349
350 int DetailsWidgetContainerExtension::count() const
351 {
352     return m_detailsWidget->widget() ? 1 : 0;
353 }
354
355 int DetailsWidgetContainerExtension::currentIndex() const
356 {
357     return 0;
358 }
359
360 void DetailsWidgetContainerExtension::insertWidget(int /* index */, QWidget *widget)
361 {
362     addWidget(widget);
363 }
364
365 void DetailsWidgetContainerExtension::remove(int /* index */)
366 {
367     m_detailsWidget->setWidget(0);
368 }
369
370 void DetailsWidgetContainerExtension::setCurrentIndex(int /* index */)
371 {
372 }
373
374 QWidget *DetailsWidgetContainerExtension::widget(int  /* index */) const
375 {
376     return m_detailsWidget->widget();
377 }
378
379 DetailsWidgetExtensionFactory::DetailsWidgetExtensionFactory(QExtensionManager *parent) :
380     QExtensionFactory(parent)
381 {
382 }
383
384 QObject *DetailsWidgetExtensionFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
385 {
386     if (Utils::DetailsWidget *dw = qobject_cast<Utils::DetailsWidget*>(object))
387         if (iid == Q_TYPEID(QDesignerContainerExtension))
388             return new DetailsWidgetContainerExtension(dw, parent);
389     return 0;
390 }
391
392 // -------------- WidgetCollection
393 WidgetCollection::WidgetCollection(QObject *parent) :
394     QObject(parent)
395 {
396     m_plugins.push_back(new NewClassCustomWidget(this));
397     m_plugins.push_back(new ClassNameValidatingLineEdit_CW(this));
398     m_plugins.push_back(new FileNameValidatingLineEdit_CW(this));
399     m_plugins.push_back(new ProjectNameValidatingLineEdit_CW(this));
400     m_plugins.push_back(new LineColumnLabel_CW(this));
401     m_plugins.push_back(new PathChooser_CW(this));
402     m_plugins.push_back(new IconButton_CW(this));
403     m_plugins.push_back(new FancyLineEdit_CW(this));
404     m_plugins.push_back(new FilterLineEdit_CW(this));
405     m_plugins.push_back(new QtColorButton_CW(this));
406     m_plugins.push_back(new SubmitEditorWidget_CW(this));
407     m_plugins.push_back(new SubmitFieldWidget_CW(this));
408     m_plugins.push_back(new PathListEditor_CW(this));
409     m_plugins.push_back(new DetailsButton_CW(this));
410     m_plugins.push_back(new DetailsWidget_CW(this));
411     m_plugins.push_back(new StyledBar_CW(this));
412     m_plugins.push_back(new StyledSeparator_CW(this));
413     m_plugins.push_back(new Wizard_CW(this));
414     m_plugins.push_back(new WelcomePageWidget_CW(this));
415     m_plugins.push_back(new WelcomeModeLabel_CW(this));
416     m_plugins.push_back(new CrumblePath_CW(this));
417 }
418
419 QList<QDesignerCustomWidgetInterface*> WidgetCollection::customWidgets() const
420 {
421     return m_plugins;
422 }
423
424 Q_EXPORT_PLUGIN(WidgetCollection)