basicwidgets.cpp 39.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
hjk's avatar
hjk committed
3
4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30

#include "basicwidgets.h"
31
#include <utils/fileutils.h>
32
#include <qlayoutobject.h>
33
34
35
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
36
#include <QDebug>
37
38
39
40
41
42
43
44
45
46
#include <QFile>
#include <QPixmap>
#include <QTimeLine>
#include <QFileInfo>
#include <QMenu>
#include <QAction>
#include <QListView>
#include <QDebug>
#include <QApplication>
#include <QGraphicsOpacityEffect>
47
48
49
50
51
52
#if QT_VERSION >= 0x050000
#  include <QFusionStyle>
#else
#  include <QCleanlooksStyle>
#  include <QPlastiqueStyle>
#endif
53
#include <QTextEdit>
54
55
56
57
58
59
60
61


QT_BEGIN_NAMESPACE

class CleanLooksSingleton
{
   public:
     static CleanLooksSingleton* instance();
62
     QStyle* style() {return &m_style; };
63
64
65

   private:
     static CleanLooksSingleton *m_instance;
66

67
68
69
#if QT_VERSION >= 0x050000
     QFusionStyle m_style;
#elif defined(Q_OS_MAC)
70
71
     QPlastiqueStyle m_style;
#else
72
     QCleanlooksStyle m_style;
73
#endif
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

     CleanLooksSingleton() {}
     CleanLooksSingleton( const CleanLooksSingleton& );

     class CleanLooksWatcher {
         public: ~CleanLooksWatcher() {
           if( CleanLooksSingleton::m_instance != 0 )
             delete CleanLooksSingleton::m_instance;
         }
     };
     friend class CleanLooksWatcher;
};

CleanLooksSingleton* CleanLooksSingleton::m_instance = 0;

CleanLooksSingleton* CleanLooksSingleton::instance()
{
  static CleanLooksWatcher w;
  if( m_instance == 0 )
    m_instance = new CleanLooksSingleton();
  return m_instance;
}
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119


class QWidgetDeclarativeUI;

class ResizeEventFilter : public QObject
{
    Q_OBJECT
public:
    ResizeEventFilter(QObject *parent) : QObject(parent), m_target(0) { }

    void setTarget(QObject *target) { m_target = target; }
    void setDuiTarget(QWidgetDeclarativeUI* dui_target) {m_dui_target = dui_target;}

protected:
    bool eventFilter(QObject *obj, QEvent *event);
private:
    QObject *m_target;
    QWidgetDeclarativeUI* m_dui_target;
};

class QWidgetDeclarativeUI : public QObject
{
    Q_OBJECT

120
    Q_PROPERTY(QDeclarativeListProperty<QObject> children READ children)
121
    Q_PROPERTY(QLayoutObject *layout READ layout WRITE setLayout)
122
    Q_PROPERTY(QDeclarativeListProperty<Action> actions READ actions)
123
    Q_PROPERTY(QFont font READ font WRITE setFont)
124
125
126
127
128
129

    Q_PROPERTY(QPoint pos READ pos)
    Q_PROPERTY(QSize size READ size)

    Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
    Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
130
131
132
133

    Q_PROPERTY(int globalX READ globalX WRITE setGlobalX)
    Q_PROPERTY(int globalY READ globalY WRITE setGlobalY)

134
135
136
137
138
    Q_PROPERTY(bool focus READ hasFocus NOTIFY focusChanged)
    Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
    Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
    Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)

139
    Q_PROPERTY(QUrl styleSheetFile READ styleSheetFile WRITE setStyleSheetFile)
140
141
142
143
144
145
146

    Q_PROPERTY(QColor windowColor READ windowColor WRITE setWindowColor)
    Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
    Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor)
    Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
    Q_PROPERTY(QColor windowTextColor READ windowTextColor WRITE setWindowTextColor)
    Q_PROPERTY(QColor buttonTextColor READ buttonTextColor WRITE setButtonTextColor)
147
    Q_PROPERTY(QColor buttonColor READ buttonColor WRITE setButtonColor)
148
149
150
151
152
153

    Q_PROPERTY(int fixedWidth READ width WRITE setFixedWidth)
    Q_PROPERTY(int fixedHeight READ height WRITE setFixedHeight)

    Q_PROPERTY(bool mouseOver READ mouseOver NOTIFY mouseOverChanged)

154
    Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
155
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
156

157
158
159
160
161
162
163
164
165
166
    Q_CLASSINFO("DefaultProperty", "children")

signals:
    void xChanged();
    void yChanged();
    void widthChanged();
    void heightChanged();
    void focusChanged();
    void mouseOverChanged();
    void opacityChanged();
167
    void visibleChanged();
168
    void enabledChanged();
169
170

public:
171
    QWidgetDeclarativeUI(QObject *other) : QObject(other), _layout(0), _graphicsOpacityEffect(0) {
172
173
174
175
176
177
        q = qobject_cast<QWidget*>(other);
        ResizeEventFilter *filter(new ResizeEventFilter(q));
        filter->setTarget(q);
        filter->setDuiTarget(this);
        m_mouseOver = false;
        q->installEventFilter(filter);
178
        q->setStyle(CleanLooksSingleton::instance()->style());
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
        Q_ASSERT(q);
    }
    virtual ~QWidgetDeclarativeUI() {
    }

public:

    void setMouseOver(bool _mouseOver)
    {
        m_mouseOver = _mouseOver;
    }

    void emitResize()
    {
        emit widthChanged();
        emit heightChanged();
    }

    void emitMove()
    {
        emit xChanged();
        emit yChanged();
    }

    void emitFocusChanged()
    {
        emit focusChanged();
    }

     void emitMouseOverChanged()
    {
        emit mouseOverChanged();
    }

Thomas Hartmann's avatar
Thomas Hartmann committed
213

214
215
216
217
218
     void emitVisibleChanged()
     {
         emit visibleChanged();
     }

219
220
221
222
223
     void emitEnabledChanged()
     {
         emit enabledChanged();
     }

Thomas Hartmann's avatar
Thomas Hartmann committed
224
225
     QDeclarativeListProperty<QObject> children() {
         return QDeclarativeListProperty<QObject>(this, 0, children_append, children_count, children_at, children_clear);
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

    QLayoutObject *layout() const { return _layout; }
    void setLayout(QLayoutObject *lo)
    {
        _layout = lo;
        static_cast<QWidget *>(parent())->setLayout(lo->layout());
    }

    QFont font() const
    {
        return _font;
    }

    void setFont(const QFont &font)
    {
        if (font != _font) {
            _font = font;
            static_cast<QWidget *>(parent())->setFont(_font);
        }
    }

    int x() const {
        return q->x();
    }

252
253
254
255
256
257
258
    int globalX() const {
        if (q->parentWidget())
            return q->mapToGlobal(QPoint(x(), 0)).x();
        else
            return x();
    }

259
260
261
262
263
264
265
266
267
268
269
270
    bool hasFocus() const {
        return q->hasFocus();
    }

    bool mouseOver() const {
        return m_mouseOver;
    }

    void setX(int x) {
        q->move(x, y());
    }

271
272
273
274
275
276
277
    void setGlobalX(int newX) {
        if (q->parentWidget())
            setX(q->mapFromGlobal(QPoint(newX, 1)).x());
        else
            setX(newX);
    }

278
279
280
281
    int y() const {
        return q->y();
    }

282
283
284
285
286
287
288
289
    bool visible() const {
        return q->isVisible();
    }

    void setVisible(bool visible) {
        q->setVisible(visible);
    }

290
291
292
293
294
295
296
297
    bool enabled() const {
        return q->isEnabled();
    }

    void setEnabled(bool enabled) {
        q->setEnabled(enabled);
    }

298
299
300
301
302
303
    int globalY() const {
        if (q->parentWidget())
            return q->mapToGlobal(QPoint(1,y())).y();
        else return y();
    }

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
    qreal opacity() const {
        if (_graphicsOpacityEffect)
            return _graphicsOpacityEffect->opacity();
        else
            return 1;
    }

    void setOpacity(qreal newOpacity) {
        if (newOpacity != opacity()) {
            if (!_graphicsOpacityEffect) {
                _graphicsOpacityEffect = new QGraphicsOpacityEffect(this);
                q->setGraphicsEffect(_graphicsOpacityEffect);
            }
            _graphicsOpacityEffect->setOpacity(newOpacity);
            emit opacityChanged();
        }
    }

    void setY(int y) {
        q->move(x(), y);
    }

326
327
328
329
330
331
332
    void setGlobalY(int newY) {
        if (q->parentWidget())
            setY(q->parentWidget()->mapFromGlobal(QPoint(1, newY)).y());
        else
            setY(newY);
    }

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
    int width() const {
        return q->width();
    }

    void setWidth(int width) {
        q->resize(width, height());
    }

    int height() const {
        return q->height();
    }

    void setHeight(int height) {
        q->resize(width(), height);
    }

    void setFixedWidth(int width) {
        q->setFixedWidth(width);
    }

    void setFixedHeight(int height) {
        q->setFixedHeight(height);
    }

    QPoint pos() const {
        return q->pos();
    }

    QSize size() const {
        return q->size();
    }

    QUrl styleSheetFile() const {
        return _styleSheetFile;
    }

    QColor windowColor() const
    { return q->palette().color(QPalette::Window); }

    void setWindowColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::Window, color);
        q->setPalette(pal);
    }

    QColor backgroundColor() const
    { return q->palette().color(QPalette::Background); }

    void setBackgroundColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::Background, color);
        q->setPalette(pal);
    }

    QColor baseColor() const
    { return q->palette().color(QPalette::Base); }

    void setBaseColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::Base, color);
        q->setPalette(pal);
    }

    QColor textColor() const
    { return q->palette().color(QPalette::Text); }

    void setTextColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::Text, color);
        q->setPalette(pal);
    }

    QColor windowTextColor() const
    { return q->palette().color(QPalette::WindowText); }

    void setWindowTextColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::WindowText, color);
        q->setPalette(pal);
    }

    QColor buttonTextColor() const
    { return q->palette().color(QPalette::ButtonText); }

    void setButtonTextColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::ButtonText, color);
        q->setPalette(pal);
    }

429
430
431
432
433
434
435
436
437
438
439
    QColor buttonColor() const
    { return q->palette().color(QPalette::Button); }

    void setButtonColor(const QColor &color)
    {
        QPalette pal = q->palette();
        pal.setColor(QPalette::Button, color);
        q->setPalette(pal);
    }


440
441
442
443
444
    void setStyleSheetFile(const QUrl &url) {
        _styleSheetFile = url;
        _styleSheetFile.setScheme("file"); //### todo
        QString fileName;
        if (!QFileInfo(_styleSheetFile.toLocalFile()).exists())
445
            fileName = (QLatin1Char(':') + _styleSheetFile.toLocalFile().split(QLatin1Char(':')).last()); //try if it is a resource
446
447
        else
            fileName = (_styleSheetFile.toLocalFile());
448
449
450
451
452
        Utils::FileReader reader;
        if (reader.fetch(fileName))
            q->setStyleSheet(QString::fromLatin1(reader.data()));
        else
            qWarning() << QString::fromLatin1("setStyleSheetFile: %1").arg(reader.errorString());
453
454
455

    }

456
457
    QDeclarativeListProperty<Action> actions() {
        return QDeclarativeListProperty<Action>(this, 0, actions_append, actions_count, actions_at, actions_clear);
458
    }
459

460
461
462
463
464
465
466
private:
    QWidget *q;
    QLayoutObject *_layout;
    QFont _font;
    QUrl _styleSheetFile;
    QGraphicsOpacityEffect *_graphicsOpacityEffect;
    bool m_mouseOver;
467

468
    static void children_append(QDeclarativeListProperty<QObject> *property, QObject *o) {
469
470
471
472
473
474
475
476
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *q = p->q;
        if (QWidget *w = qobject_cast<QWidget *>(o))
            w->setParent(static_cast<QWidget *>(q));
        else
            o->setParent(q);
    }

477
    static int children_count(QDeclarativeListProperty<QObject> *property) {
478
479
480
481
482
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *q = p->q;
        return q->children().count();
    }

483
    static QObject * children_at(QDeclarativeListProperty<QObject> *property, int index) {
484
485
486
487
488
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *q = p->q;
        return q->children().at(index);
    }

489
    static void children_clear(QDeclarativeListProperty<QObject> *property) {
490
491
492
493
494
495
496
497
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *q = p->q;
        QObjectList c = q->children();
        for (int i = 0; i < c.count(); ++i)
            c.at(i)->setParent(0);
    }

    // ### Original had an insert, and removeAt
498
    static void actions_append(QDeclarativeListProperty<Action> *property, Action *o) {
499
500
501
502
503
504
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *w = p->q;
        o->setParent(w);
        w->addAction(o);
    }

505
    static int actions_count(QDeclarativeListProperty<Action> *property) {
506
507
508
509
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *w = p->q;
        return w->actions().count();
    }
510
    static Action *actions_at(QDeclarativeListProperty<Action> *property, int index) {
511
512
513
514
515
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *w = p->q;
        return qobject_cast<Action *>(w->actions().at(index));
    }

516
    static void actions_clear(QDeclarativeListProperty<Action> *property) {
517
518
519
520
521
522
        QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
        QWidget *w = p->q;

        while (!w->actions().empty())
            w->removeAction(w->actions().first());
    }
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
};

bool ResizeEventFilter::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::Resize) {
        if (obj
            && obj->isWidgetType()
            && obj == m_target) {
                m_dui_target->emitResize();
                return QObject::eventFilter(obj, event);
        }
    } else if (event->type() == QEvent::Move) {
        if (obj
            && obj->isWidgetType()
            && obj == m_target) {
                m_dui_target->emitMove();
                return QObject::eventFilter(obj, event);
        }
    } else if ((event->type() == QEvent::FocusIn) || (event->type() == QEvent::FocusOut)) {
        if (obj
            && obj->isWidgetType()
            && obj == m_target) {
                m_dui_target->emitFocusChanged();
                return QObject::eventFilter(obj, event);
        }
    } else if ((event->type() == QEvent::Enter) || (event->type() == QEvent::Leave)) {
        if (obj
            && obj->isWidgetType()
            && obj == m_target) {
                m_dui_target->setMouseOver(event->type() == QEvent::Enter);
                m_dui_target->emitMouseOverChanged();
                return QObject::eventFilter(obj, event);
        }
556
557
558
559
560
561
    } else if ((event->type() == QEvent::Show) || (event->type() == QEvent::Hide)) {
        if (obj
            && obj->isWidgetType()
            && obj == m_target) {
                m_dui_target->emitVisibleChanged();
                return QObject::eventFilter(obj, event);
562
563
564
565
566
567
568
569
            }
    } else if (event->type() == QEvent::EnabledChange) {
        if (obj
            && obj->isWidgetType()
            && obj == m_target) {
                m_dui_target->emitEnabledChanged();
                return QObject::eventFilter(obj,event);
            }
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
    }
    return QObject::eventFilter(obj, event);
}


class QTabObject : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QWidget *content READ content WRITE setContent)
    Q_PROPERTY(QString label READ label WRITE setLabel)
    Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
    Q_CLASSINFO("DefaultProperty", "content")
public:
    QTabObject(QObject *parent = 0) : QObject(parent), _content(0) {}

    QWidget *content() const { return _content; }
    void setContent(QWidget *content)
    {
        _content = content;
    }

    QString label() const { return _label; }
    void setLabel(const QString &label)
    {
        _label = label;
    }

    QIcon icon() const { return _icon; }
    void setIcon(const QIcon &icon)
    {
        _icon = icon;
    }

private:
    QWidget *_content;
    QString _label;
    QIcon _icon;
};

class QPushButtonDeclarativeUI : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QUrl iconFromFile READ iconFromFile WRITE setIconFromFile)
public:
    QPushButtonDeclarativeUI(QObject *parent = 0) : QObject(parent)
     {
         pb = qobject_cast<QPushButton*>(parent);
     }
private:
    QUrl iconFromFile() const
    {
        return _url;
    }

    void setIconFromFile(const QUrl &url) {
        _url = url;

        QString path;
        if (_url.scheme() == QLatin1String("qrc")) {
631
            path = QLatin1Char(':') + _url.path();
632
633
634
635
636
        } else {
            path = _url.toLocalFile();
        }

        QFile file(path);
637
        if (file.open(QIODevice::ReadOnly)) {
638
639
            QPixmap pixmap(path);
            if (pixmap.isNull())
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
640
                qWarning() << "setIconFromFile: failed to load" << path;
641
642
            pb->setIcon(pixmap);
        } else {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
643
            qWarning() << QString::fromLatin1("setIconFromFile: %1: %2").arg(path, file.errorString());
644
645
646
647
648
649
650
651
        }

    }

    QPushButton *pb;
    QUrl _url;
};

652
653
654
655
656
657
658
659
class ElidingLabel : public QLabel
{
    Q_OBJECT
public:
    ElidingLabel(QWidget * parent = 0) : QLabel(parent) {}

protected:
    void paintEvent(QPaintEvent *event)
660
    {
661
        QFontMetrics fm(font());
662
        if (fm.width(text()) > (contentsRect().width() - 8) && text().length() > 4) {
663
            QPainter p(this);
664
665
666
            QString elided_txt;            
            elided_txt = fm.elidedText(text(), Qt::ElideRight, contentsRect().width() - 8, Qt::TextShowMnemonic);
            p.drawText(contentsRect().adjusted(12, 0, 0, 0), Qt::TextSingleLine, elided_txt);
667
668
669
670
671
672
673
        }
        else
            QLabel::paintEvent(event);
       }

};

674
675
676
677
678
679
680
681
682

class QLabelDeclarativeUI : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QUrl iconFromFile READ iconFromFile WRITE setIconFromFile)
public:
    QLabelDeclarativeUI(QObject *parent = 0) : QObject(parent)
     {
683
         lb = qobject_cast<ElidingLabel*>(parent);
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
     }
private:
    QUrl iconFromFile() const
    {
        return _url;
    }

    void setIconFromFile(const QUrl &url) {
        _url = url;

        QString path;
        if (_url.scheme() == QLatin1String("qrc")) {
            path = QLatin1Char(':') + _url.path();
        } else {
            path = _url.toLocalFile();
        }

        QFile file(path);
702
        if (file.open(QIODevice::ReadOnly)) {
703
704
            QPixmap pixmap(path);
            if (pixmap.isNull())
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
705
                qWarning() << "setIconFromFile: failed to load" << path;
706
707
            lb->setPixmap(pixmap);
        } else {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
708
            qWarning() << QString::fromLatin1("setIconFromFile: %1: %2").arg(path, file.errorString());
709
710
711
712
        }

    }

713
    ElidingLabel *lb;
714
715
716
    QUrl _url;
};

717
718
719
720
721
722
723
class QMenuDeclarativeUI : public QObject
{
    Q_OBJECT

    Q_CLASSINFO("DefaultProperty", "actions")

public:
724
    QMenuDeclarativeUI(QObject *parent = 0) : QObject(parent)
725
726
727
728
729
     {
         menu = qobject_cast<QMenu*>(parent);
     }

private:
730
    //if not for the at() function, we could use QDeclarativeList instead
731
732

    QMenu *menu;
733

734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
};

class QToolButtonDeclarativeUI : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QUrl iconFromFile READ iconFromFile WRITE setIconFromFile)
    Q_PROPERTY(QMenu *menu READ menu WRITE setMenu)

public:
    QToolButtonDeclarativeUI(QObject *parent = 0) : QObject(parent)
     {
         pb = qobject_cast<QToolButton*>(parent);
     }
private:

    QMenu *menu() const { return pb->menu(); }
    void setMenu(QMenu *menu)
    {
753
        menu->setParent(0);
754
        pb->setMenu(menu);
755
        menu->setParent(QApplication::topLevelWidgets().first());
756
757
758
759
760
761
762
763
764
765
766
767
    }

    QUrl iconFromFile() const
    {
        return _url;
    }

    void setIconFromFile(const QUrl &url) {
        _url = url;

        QString path;
        if (_url.scheme() == QLatin1String("qrc")) {
768
            path = QLatin1Char(':') + _url.path();
769
770
771
772
773
        } else {
            path = _url.toLocalFile();
        }

        QFile file(path);
774
        if (file.open(QIODevice::ReadOnly)) {
775
776
            QPixmap pixmap(path);
            if (pixmap.isNull())
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
777
                qWarning() << "setIconFromFile: failed to load" << path;
778
779
            pb->setIcon(pixmap);
        } else {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
780
            qWarning() << QString::fromLatin1("setIconFromFile: %1: %2").arg(path, file.errorString());
781
782
783
784
785
786
787
788
        }

    }

    QToolButton *pb;
    QUrl _url;
};

789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
class AnimatedToolButton : public QToolButton
{

Q_OBJECT

    Q_PROPERTY(QUrl hoverIconFromFile READ hoverIconFromFile WRITE setHoverIconFromFile)

public:
    AnimatedToolButton( QWidget * parent = 0 ) : QToolButton(parent)
    {}

private:
    QUrl hoverIconFromFile() const
    { return m_hoverIconUrl; }

    void setHoverIconFromFile(const QUrl &url)
    {  m_hoverIconUrl= url;
       m_hoverIcon = QIcon(m_hoverIconUrl.toLocalFile());
    }

    void leaveEvent(QEvent *)
    {
        setIcon(m_icon);
    }

    void enterEvent(QEvent *)
    {
        m_icon = icon();
        setIcon(m_hoverIcon);
    }

    QUrl m_hoverIconUrl;
    QIcon m_hoverIcon;
    QIcon m_icon;

};

826
827
828
class QComboBoxDeclarativeUI : public QObject
{
     Q_OBJECT
829
     Q_PROPERTY(QStringList items READ items WRITE setItems)
830
831
832
833
834
835
     Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText NOTIFY currentTextChanged)

public:
     QComboBoxDeclarativeUI(QObject *parent = 0) : QObject(parent), m_itemsSet(false)
     {
         cb = qobject_cast<QComboBox*>(parent);
Robert Loehning's avatar
Robert Loehning committed
836
         connect(cb, SIGNAL(currentIndexChanged(QString)), this, SLOT(setCurrentText(QString)));
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
     }

     QString currentText() const
     {
         return cb->currentText();
     }

public slots:
     void setCurrentText(const QString &text)
     {
         if (!m_itemsSet)
             return;
         int i = cb->findText(text);
         if (i  != -1) {
             cb->setCurrentIndex(i);
             emit currentTextChanged();
         }
     }
855
856
857
858
859
860
861
862
863
864
865
866
public slots:
     void setCurrentTextSilent(const QString &text)
     {
         if (!m_itemsSet)
             return;
         int i = cb->findText(text);
         if (i  != -1) {
             blockSignals(true);
             cb->setCurrentIndex(i);
             blockSignals(false);
         }
     }
867
868
869
870
871
872
873
874
875
signals:
    void currentTextChanged();
    void itemsChanged();

private:
    void setItems(const QStringList &list)
    {
        _items = list;
        cb->clear();
876
        blockSignals(true);
877
878
        cb->addItems(list);
        m_itemsSet = true;
879
        blockSignals(false);
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
        emit itemsChanged();
    }

    QStringList items() const
    {
        return _items;
    }

    QComboBox *cb;
    QStringList _items;

    bool m_itemsSet;
};

class QScrollAreaDeclarativeUI : public QObject
{
     Q_OBJECT
     Q_PROPERTY(QWidget *content READ content WRITE setContent)
     Q_CLASSINFO("DefaultProperty", "content")

public:
     QScrollAreaDeclarativeUI(QObject *parent = 0) : QObject(parent), _content(0)
     {
         sa = qobject_cast<QScrollArea*>(parent);
     }

private:
    QWidget *content() const { return _content; }
    void setContent(QWidget *content)
    {
        _content = content;
        sa->setWidget(content);
        sa->verticalScrollBar()->show();
    }

    QWidget *_content;
    QScrollArea *sa;
};


class WidgetLoader : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(QString sourceString READ sourceString WRITE setSourceString NOTIFY sourceChanged)
    Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
925
    Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl)
926
    Q_PROPERTY(QString qmlData READ qmlData WRITE setQmlData NOTIFY qmlDataChanged)
927
    Q_PROPERTY(QWidget *widget READ widget NOTIFY widgetChanged)
928
    Q_PROPERTY(QDeclarativeComponent *component READ component NOTIFY sourceChanged)
929
930
931
932
933
934
935
936
937
938
939

public:
    WidgetLoader(QWidget * parent = 0) : QWidget(parent), m_source(QUrl()), m_widget(0),
                                         m_component(0), m_layout(0)
    {
        m_layout = new QVBoxLayout(this);
        m_layout->setContentsMargins(0,0,0,0);
    }

    QUrl source() const;
    void setSource(const QUrl &);
940
941
    QString qmlData() const;
    void setQmlData(const QString &data);
942
943
944
945
946
947
948

    QString sourceString() const
    { return m_source.toString(); }
    void setSourceString(const QString &url)
    { setSource(QUrl(url)); }

    QWidget *widget() const;
949
    QDeclarativeComponent *component() const
950
951
    { return m_component; }

952
953
954
955
    void setBaseUrl(const QUrl &baseUrl);

    QUrl baseUrl() const;

956
957
958
signals:
    void widgetChanged();
    void sourceChanged();
959
    void qmlDataChanged();
960
961
962

private:
    QUrl m_source;
963
964
    QUrl m_baseUrl;
    QString m_qmlData;
965
    QWidget *m_widget;
966
    QDeclarativeComponent *m_component;
967
    QVBoxLayout *m_layout;
968
    QHash<QString, QWidget*> m_cachedWidgets;
969
970
971
972
973
974
975
};

QUrl WidgetLoader::source() const
{
    return m_source;
}

976
QUrl WidgetLoader::baseUrl() const
977
{
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
    return m_baseUrl;
}

void WidgetLoader::setBaseUrl(const QUrl &baseUrl)
{
    if (m_baseUrl == baseUrl)
        return;
    m_baseUrl = baseUrl;
}

QString WidgetLoader::qmlData() const
{
    return m_qmlData;
}

void WidgetLoader::setQmlData(const QString &data)
{
    if (m_qmlData == data)
        return;

    m_qmlData = data;

    setSource(QUrl());

    foreach (QWidget *cachedWidget, m_cachedWidgets)
        cachedWidget->hide();

    if (m_qmlData.isEmpty()) {
        emit sourceChanged();
        emit widgetChanged();
1008
        return;
1009
    }
1010
1011
1012
1013
1014
1015

    if (m_component) {
        delete m_component;
        m_component = 0;
    }

1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
    QString stringHash = QString::number(qHash(data));

    if (m_cachedWidgets.contains(stringHash)) {
        m_widget = m_cachedWidgets.value(stringHash);
        m_widget->show();
    } else {
        m_component = new QDeclarativeComponent(qmlEngine(this), this);
        m_component->setData (m_qmlData.toLatin1(), m_baseUrl);
        if (m_component) {
            emit sourceChanged();
            emit widgetChanged();

            while (m_component->isLoading())
                QApplication::processEvents();

            if (!m_component->isReady()) {
                if (!m_component->errors().isEmpty())
                    qWarning() << m_component->errors();
                emit sourceChanged();
                return;
            }

            QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(this));
            ctxt->setContextObject(this);
            QObject *obj = m_component->create(ctxt);
            if (obj) {
                QWidget *widget = qobject_cast<QWidget *>(obj);
                if (widget) {
                    m_cachedWidgets.insert(stringHash, widget);
                    m_widget = widget;
                    m_layout->addWidget(m_widget);
                    m_widget->show();
                }
            }
        }
    }

}

void WidgetLoader::setSource(const QUrl &source)
{
    if (m_source == source)
        return;

    setQmlData("");

Marco Bubke's avatar
Marco Bubke committed
1062
//    QWidget *oldWidget = m_widget;
1063
1064
1065

    if (m_widget) {
        //m_widget->deleteLater();
1066
        m_widget->hide();
1067
1068
1069
        m_widget = 0;
    }

1070
1071
1072
    foreach (QWidget *cachedWidget, m_cachedWidgets)
        cachedWidget->hide();

1073
1074
1075
1076
1077
1078
1079
    m_source = source;
    if (m_source.isEmpty()) {
        emit sourceChanged();
        emit widgetChanged();
        return;
    }

1080
1081
1082
1083
1084
    if (m_component) {
        delete m_component;
        m_component = 0;
    }

1085
1086
1087
1088
    if (m_cachedWidgets.contains(source.toString())) {
        m_widget = m_cachedWidgets.value(source.toString());
        m_widget->show();
    } else {
1089
        m_component = new QDeclarativeComponent(qmlEngine(this), m_source, this);
1090

1091
        if (m_component) {
1092
            emit sourceChanged();
1093
            emit widgetChanged();
1094

1095
1096
            while (m_component->isLoading())
                QApplication::processEvents();
1097

1098
1099
1100
1101
1102
1103
1104
            if (!m_component->isReady()) {
                if (!m_component->errors().isEmpty())
                    qWarning() << m_component->errors();
                emit sourceChanged();
                return;
            }

1105
            QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(this));
1106
            ctxt->setContextObject(this);
1107
1108
1109
1110
1111
1112
1113
1114
1115
            QObject *obj = m_component->create(ctxt);
            if (obj) {
                QWidget *widget = qobject_cast<QWidget *>(obj);
                if (widget) {
                    m_cachedWidgets.insert(source.toString(), widget);
                    m_widget = widget;
                    m_layout->addWidget(m_widget);
                    m_widget->show();
                }
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
            }
        }
    }
}

QWidget *WidgetLoader::widget() const
{
    return m_widget;
}

class MyGroupBox : public QGroupBox
{
     Q_OBJECT

1130
1131
    Q_PROPERTY(bool animated READ isAnimated)

1132
public:
1133
    MyGroupBox(QWidget * parent = 0) : QGroupBox(parent), m_animated(false), m_firstExpand(true)
1134
1135
1136
1137
1138
1139
1140
1141
    {}

void setPixmap(const QPixmap &pixmap, qreal alpha = 1)
{ m_pixmap = pixmap; m_alpha = alpha;}

void setAnimated(bool animated)
{ m_animated = animated; }

1142
1143
1144
void finishFirstExpand()
{ m_firstExpand = false; }

1145
1146
1147
bool isAnimated()
{ return m_animated; }

1148
1149
1150
1151
1152
1153
1154
1155
1156
public slots:
    virtual void setVisible ( bool visible );

protected:
    virtual void paintEvent(QPaintEvent * event);
private:
    qreal m_alpha;
    QPixmap m_pixmap;
    bool m_animated;
1157
    bool m_firstExpand;
1158
1159
1160
1161
1162
1163
1164
};

void MyGroupBox::paintEvent(QPaintEvent * event)
{
    QGroupBox::paintEvent(event);
    if (m_animated) {
        QPainter p(this);
Bill King's avatar
Bill King committed
1165
1166
        if (!m_pixmap.isNull() && !m_firstExpand) {
            p.setOpacity(m_alpha);
1167
            p.drawPixmap(5, 5,  m_pixmap.width(), m_pixmap.height(), m_pixmap);
Bill King's avatar
Bill King committed
1168
        }
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
    }
}

void MyGroupBox::setVisible ( bool visible )
{
    if (parentWidget())
        QGroupBox::setVisible(visible);
}

class QGroupBoxDeclarativeUI : public QObject
{
    Q_OBJECT

    Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed)
1183
    Q_PROPERTY(bool smooth READ isSmooth WRITE setSmooth)
1184
1185
1186
1187
public:
    QGroupBoxDeclarativeUI(QObject *parent = 0) : QObject(parent), m_expanded(true)
    {
        gb =  qobject_cast<MyGroupBox*>(parent);
1188
        connect(&m_timeLine, SIGNAL (frameChanged(int)), this, SLOT(animate(int)));
1189
1190
        connect(&m_timeLine, SIGNAL(finished()), this, SLOT(finish()));

1191
        m_timeLine.setDuration(100);
1192
        m_timeLine.setFrameRange(0, 5);
1193
        m_smooth = true;
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
    }

    bool isCollapsed()
    { return ! m_expanded; }

    void setCollapsed(bool collapsed)
    {
        if (collapsed)
            collapse();
        else
            expand();
    }

1207
1208
1209
1210
1211
    bool isSmooth()
    { return m_smooth; }
    void setSmooth(bool smooth)
    { m_smooth = smooth; }

1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
public slots:
    void collapse();
    void expand();

    void animate(int frame);
    void finish();

private:
    MyGroupBox *gb;
    QTimeLine m_timeLine;
    bool m_expanded;
    int m_oldHeight;
    int m_oldMAxHeight;
1225
    int m_oldMinHeight;
1226
    QPixmap m_contens;
1227
    bool m_smooth;
1228
1229
1230
1231
1232
1233
1234
1235
1236

    void hideChildren();
    void showChildren();

    void reLayout();
};

void QGroupBoxDeclarativeUI::reLayout()
{
1237
    gb->setUpdatesEnabled(false);
1238
    QLayout *layout = gb->parentWidget()->layout();
1239
    QPoint oldPos = gb->pos();
1240
    if (layout) {
1241
        layout->invalidate();
1242
1243
        layout->activate();
    }
1244
1245
1246
    gb->move(oldPos);
    gb->setUpdatesEnabled(true);
    gb->update();
1247
1248
1249
1250
1251
1252
}

void QGroupBoxDeclarativeUI::finish()
{
    if (m_expanded) {
        showChildren();
1253
        gb->setUpdatesEnabled(false);
1254
        gb->setMinimumHeight(m_oldMinHeight);
1255
        gb->setMaximumHeight(m_oldMAxHeight);
1256
1257
        gb->setUpdatesEnabled(true);
        //gb->resize(gb->sizeHint());
1258
        gb->finishFirstExpand();
1259
1260
    }
    else {
1261
        gb->setMinimumHeight(30);
1262
        gb->setMaximumHeight(30);
1263
        gb->resize(gb->sizeHint().width(), 30);
1264
1265
    }
    reLayout();
1266
    gb->setAnimated(false);
1267
1268
1269
1270
1271
1272
1273
}

void QGroupBoxDeclarativeUI::hideChildren()
{
    if (gb->isVisible()) {
        gb->setMinimumHeight(gb->height());
        foreach (QWidget *widget, gb->findChildren<QWidget*>())
1274
1275
            if (widget->parent() == gb) {
                widget->setProperty("wasVisibleGB", widget->property("visible"));
1276
                widget->hide();
1277
            }
1278
1279
1280
1281
1282
1283
    }
}

void QGroupBoxDeclarativeUI::showChildren()
{
    foreach (QWidget *widget, gb->findChildren<QWidget*>()) {
1284
1285
1286
1287
1288
1289
        if (widget->parent() == gb) {
            if (widget->property("wasVisibleGB").toBool())
                widget->show();
            widget->setProperty("wasVisibleGB", QVariant());
            widget->ensurePolished();
        }
1290
1291
1292
1293
1294
1295
1296
1297
    }
    gb->show();
}

void QGroupBoxDeclarativeUI::collapse()
{
    m_oldMAxHeight = gb->maximumHeight();
    m_oldHeight = gb->height();
1298
    m_oldMinHeight =gb->minimumHeight();
1299
1300
    if (!m_expanded)
        return;
1301
1302
1303
1304
1305
1306

#if QT_VERSION < 0x050000
    m_contens = QPixmap::grabWidget(gb, 5, 5, gb->width() - 5, gb->height() - 5);
#else
    m_contens = gb->grab(QRect(5, 5, gb->width() - 5, gb->height() - 5));
#endif
1307
    gb->setPixmap(m_contens,1);
1308
    hideChildren();
1309
    m_expanded = false;
1310
    gb->setAnimated(true);
1311
1312
1313
1314
1315
1316
1317
1318
    m_timeLine.start();
}

void QGroupBoxDeclarativeUI::expand()
{
    if (m_expanded)
        return;
    m_expanded = true;
1319
    gb->setAnimated(true);
1320
1321
1322
1323
1324
    m_timeLine.start();
}

void QGroupBoxDeclarativeUI::animate(int frame)
{
1325
1326
    if (!m_smooth)
        return;
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
    qreal height;

    if (m_expanded) {
        height = ((qreal(frame) / 5.0) * qreal(m_oldHeight)) + (30.0 * (1.0 - qreal(frame) / 5.0));
        gb->setPixmap(m_contens, qreal(frame) / 5.0);
    }
    else {
        height = ((qreal(frame) / 5.0) * 30.0) + (qreal(m_oldHeight) * (1.0 - qreal(frame) / 5.0));
        qreal alpha = 0.8 - qreal(frame) / 4.0;
        if (alpha < 0)
            alpha = 0;
        gb->setPixmap(m_contens, alpha);
    }

    gb->setMaximumHeight(height);
    gb->setMinimumHeight(height);
    reLayout();
}

class QTabWidgetDeclarativeUI : public QObject
{
    Q_OBJECT

1350
    Q_PROPERTY(QDeclarativeListProperty<QTabObject> tabs READ tabs)
1351
1352
    Q_CLASSINFO("DefaultProperty", "tabs")
public:
1353
    QTabWidgetDeclarativeUI(QObject *other) : QObject(other) {}
1354

1355
1356
    QDeclarativeListProperty<QTabObject> tabs() {
        return QDeclarativeListProperty<QTabObject>(this, 0, tabs_append, 0, 0, tabs_clear);
1357
    }
1358
1359

private:
1360
    static void tabs_append(QDeclarativeListProperty<QTabObject> *property, QTabObject *o) {
1361
1362
1363
1364
1365
1366
1367
        QTabWidget *tw = static_cast<QTabWidget*>(property->object->parent());
        if (!o->icon().isNull())
            tw->addTab(o->content(), o->icon(), o->label());
        else
            tw->addTab(o->content(), o->label());
    }

1368
    static void tabs_clear(QDeclarativeListProperty<QTabObject> *property) {
1369
1370
1371
        QTabWidget *tw = static_cast<QTabWidget*>(property->object->parent());
        tw->clear();
    }
1372
1373
};

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
class ExpressionEdit : public QPlainTextEdit
{
    Q_OBJECT
public:
    ExpressionEdit(QWidget *parent = 0) : QPlainTextEdit(parent) {}
signals:
    void returnPressed();

protected:
    void keyPressEvent( QKeyEvent * e );
};

void ExpressionEdit::keyPressEvent(QKeyEvent * e)
{
    if ((e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) && (e->modifiers() == Qt::NoModifier))
        emit returnPressed();
    else
        QPlainTextEdit::keyPressEvent(e);
}

1394
1395
1396
1397
1398
1399
1400
1401
1402

class WidgetFrame : public QFrame
{
    Q_OBJECT
public:
    WidgetFrame( QWidget * parent = 0, Qt::WindowFlags f = 0 ) : QFrame(parent, f)
    {}
};

hjk's avatar
hjk committed
1403
QT_END_NAMESPACE
1404

1405
1406
1407
1408
1409
QML_DECLARE_TYPE(QTabObject)
QML_DECLARE_TYPE(MyGroupBox)
QML_DECLARE_TYPE(WidgetLoader)
QML_DECLARE_TYPE(WidgetFrame)
QML_DECLARE_TYPE(AnimatedToolButton)
1410
1411
1412

void BasicWidgets::registerDeclarativeTypes()
{
Roberto Raggi's avatar
Roberto Raggi committed
1413
    qmlRegisterExtendedType<QWidget,QWidgetDeclarativeUI>("Bauhaus",1,0,"QWidget");
1414
1415

    //display
Roberto Raggi's avatar
Roberto Raggi committed
1416
1417
    qmlRegisterType<QProgressBar>("Bauhaus",1,0,"QProgressBar");
    qmlRegisterType<QLCDNumber>("Bauhaus",1,0,"QLCDNumber");
1418
1419

    //input
Roberto Raggi's avatar
Roberto Raggi committed
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
    qmlRegisterType<QLineEdit>("Bauhaus",1,0,"QLineEdit");
    qmlRegisterType<QTextEdit>("Bauhaus",1,0,"QTextEdit");
    qmlRegisterType<ExpressionEdit>("Bauhaus",1,0,"ExpressionEdit");
    qmlRegisterType<QPlainTextEdit>("Bauhaus",1,0,"QPlainTextEdit");
    qmlRegisterType<QSpinBox>("Bauhaus",1,0,"QSpinBox");
    qmlRegisterType<QDoubleSpinBox>("Bauhaus",1,0,"QDoubleSpinBox");
    qmlRegisterType<QSlider>("Bauhaus",1,0,"QSlider");
    qmlRegisterType<QDateTimeEdit>("Bauhaus",1,0,"QDateTimeEdit");
    qmlRegisterType<QDateEdit>("Bauhaus",1,0,"QDateEdit");
    qmlRegisterType<QTimeEdit>("Bauhaus",1,0,"QTimeEdit");
    qmlRegisterType<QFontComboBox>("Bauhaus",1,0,"QFontComboBox");
    qmlRegisterType<QDial>("Bauhaus",1,0,"QDial");
    qmlRegisterType<QScrollBar>("Bauhaus",1,0,"QScrollBar");
    qmlRegisterType<QCalendarWidget>("Bauhaus",1,0,"QCalendarWidget");


    //qmlRegisterType<>("Bauhaus",1,0,QComboBox,QComboBox); //need a way to populate
1437
1438
1439
    //QML_REGISTER_EXTENDED_TYPE(QComboBox,QComboBox, QComboBox); //need a way to populate

    //buttons
Roberto Raggi's avatar
Roberto Raggi committed
1440
1441
1442
1443
1444
1445
1446
    //qmlRegisterType<>("Bauhaus",1,0,QPushButton,QPushButton);
    qmlRegisterType<QCheckBox>("Bauhaus",1,0,"QCheckBox");
    qmlRegisterType<QGroupBox>("Bauhaus",1,0,"QGroupBox");
    qmlRegisterType<Action>("Bauhaus",1,0,"QAction");
    qmlRegisterType<QRadioButton>("Bauhaus",1,0,"QRadioButton");
    qmlRegisterType<FileWidget>("Bauhaus",1,0,"FileWidget");
    qmlRegisterType<LayoutWidget>("Bauhaus",1,0,"LayoutWidget");
1447
1448

    //containers
Roberto Raggi's avatar
Roberto Raggi committed
1449
1450
1451
    qmlRegisterType<QFrame>("Bauhaus",1,0,"QFrame");
    qmlRegisterType<WidgetFrame>("Bauhaus",1,0,"WidgetFrame");
    qmlRegisterType<WidgetLoader>("Bauhaus",1,0,"WidgetLoader");
1452
    qmlRegisterType<AnimatedToolButton>("Bauhaus",1,0,"AnimatedToolButton");
Roberto Raggi's avatar
Roberto Raggi committed
1453
1454
1455
1456
    qmlRegisterExtendedType<MyGroupBox,QGroupBoxDeclarativeUI>("Bauhaus",1,0,"QExtGroupBox");
    qmlRegisterExtendedType<QTabWidget,QTabWidgetDeclarativeUI>("Bauhaus",1,0,"QTabWidget");
    qmlRegisterExtendedType<QScrollArea,QScrollAreaDeclarativeUI>("Bauhaus",1,0,"QScrollArea");
    qmlRegisterExtendedType<QPushButton,QPushButtonDeclarativeUI>("Bauhaus",1,0,"QPushButton");
1457
    qmlRegisterExtendedType<ElidingLabel,QLabelDeclarativeUI>("Bauhaus",1,0,"QLabel");
Roberto Raggi's avatar
Roberto Raggi committed
1458
1459
1460
1461
1462
    qmlRegisterExtendedType<QToolButton, QToolButtonDeclarativeUI>("Bauhaus",1,0,"QToolButton");
    qmlRegisterExtendedType<QComboBox, QComboBoxDeclarativeUI>("Bauhaus",1,0,"QComboBox");
    qmlRegisterExtendedType<QMenu, QMenuDeclarativeUI>("Bauhaus",1,0,"QMenu");
    //qmlRegisterType<>("Bauhaus",1,0,BauhausoolBox,BauhausoolBox);
    //qmlRegisterType<>("Bauhaus",1,0,QScrollArea,QScrollArea);
1463
1464
1465
1466

    //QML_REGISTER_EXTENDED_TYPE(BauhausColorButton,BauhausColorButton,BauhausColorButtonDeclarativeUI);

    //itemviews
Roberto Raggi's avatar
Roberto Raggi committed
1467
1468
1469
    //qmlRegisterType<>("Bauhaus",1,0,QListView,QListView);
    //qmlRegisterType<>("Bauhaus",1,0,BauhausreeView,BauhausreeView);
    //qmlRegisterType<>("Bauhaus",1,0,BauhausableView,BauhausableView);
1470

Roberto Raggi's avatar
Roberto Raggi committed
1471
    qmlRegisterType<QTabObject>("Bauhaus",1,0,"QTabObject"); //### with namespacing, this should just be 'Tab'
1472
}
1473
1474

#include "basicwidgets.moc"