diff --git a/components/Button.qml b/components/Button.qml index b0df9273be2439c07698cf22a7407b3eed10ad73..4ba2b8d6a24afab8d24e31ea336c615f9a374d0e 100644 --- a/components/Button.qml +++ b/components/Button.qml @@ -4,7 +4,7 @@ import "custom" as Components Components.Button { id: button - width: Math.max(80, sizehint.width) + width: Math.max(72, sizehint.width) height: Math.max(22, sizehint.height) property alias containsMouse: tooltip.containsMouse diff --git a/components/Dialog.qml b/components/Dialog.qml new file mode 100644 index 0000000000000000000000000000000000000000..a80a0cd7eb7c6d54d51afd4cbd4d52b5f1df2b43 --- /dev/null +++ b/components/Dialog.qml @@ -0,0 +1,74 @@ +import QtQuick 1.0 + +Window { + id: dialog + + width: 400 + height: 200 + + signal finished + signal accepted + signal rejected + + property int ok: 0x00000400 + property int cancel: 0x00400000 + property int close: 0x00200000 + property int help: 0x02000000 + + property int buttons: ok | cancel + + modal: true + + default property alias data: content.data + + Item { + id: content + anchors.topMargin:8 + anchors.margins: 16 + anchors.top: parent.top + anchors.right: parent.right + anchors.left: parent.left + anchors.bottom: buttonrow.top + } + + // Dialogs should center on parent + onVisibleChanged: center() + + Row { + id: buttonrow + + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.margins: 16 + anchors.bottomMargin:8 + spacing: 6 + + Button { + visible: buttons & help + text: "Help" + onClicked: { + visible: dialog.visible = false + rejected() + } + } + + Button { + visible: buttons & cancel + text: "Cancel" + onClicked: { + visible: dialog.visible = false + rejected() + } + } + + Button { + visible: buttons & ok + text: "OK" + defaultbutton: true + onClicked: { + visible: dialog.visible = false + accepted() + } + } + } +} diff --git a/components/components.pro b/components/components.pro index a112b47c59430e4b29bb036b61365237581ed77c..0dd9ab39ebba4bf29e0f3c4b399e7da79f537c4e 100644 --- a/components/components.pro +++ b/components/components.pro @@ -12,6 +12,7 @@ QML_FILES = \ Button.qml \ ComboBox.qml \ Dial.qml \ + Dialog.qml \ ProgressBar.qml \ ScrollBar.qml \ Switch.qml \ diff --git a/components/qmldir b/components/qmldir index c4bf902f5f74ab08221c4cc5989db291bafd54a1..e90008df18305a707a0135f8780b3b0ab24439e5 100644 --- a/components/qmldir +++ b/components/qmldir @@ -27,3 +27,4 @@ plugin styleplugin plugin TableColumn 0.1 TableColumn.qml ContextMenu 0.1 ContextMenu.qml MenuItem 0.1 MenuItem.qml +Dialog 0.1 Dialog.qml diff --git a/examples/Gallery.qml b/examples/Gallery.qml index b1a8a66d3ad4a40db3d214238c8b8bc3e09f2dee..eab71dedb024e302d89662c9b485f4ce3596a816 100644 --- a/examples/Gallery.qml +++ b/examples/Gallery.qml @@ -13,7 +13,7 @@ Rectangle { width: 538 + frame.margins * 2 height: 360 + frame.margins * 2 - ToolBar{ + ToolBar { id: toolbar width: parent.width height: 40 diff --git a/src/qstyleitem.cpp b/src/qstyleitem.cpp index 7e92975a12a204b54020f8b6a09f292cb741c1bd..9e599600e354ef941a9765de246cc6c4fc207bcc 100644 --- a/src/qstyleitem.cpp +++ b/src/qstyleitem.cpp @@ -542,8 +542,15 @@ QSize QStyleItem::sizeFromContents(int width, int height) case ToolButton: size = qApp->style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(width,height), widget()); break; - case Button: - size = qApp->style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(width,height), widget()); + case Button:{ + QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); + int textWidth = btn->fontMetrics.width(btn->text); + size = qApp->style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(textWidth,height), widget()); +#ifdef Q_WS_MAC + // Macstyle adds some weird constants to buttons + return QSize(textWidth + 14, size.height()); +#endif +} break; case Tab: size = qApp->style()->sizeFromContents(QStyle::CT_TabBarTab, m_styleoption, QSize(width,height), widget()); diff --git a/src/qtoplevelwindow.cpp b/src/qtoplevelwindow.cpp index b233183a1b72e4e2816281ed918a579ff6a593b8..23849cded71c272e2d4c0f15f6e469b34075a760 100644 --- a/src/qtoplevelwindow.cpp +++ b/src/qtoplevelwindow.cpp @@ -8,6 +8,7 @@ QTopLevelWindow::QTopLevelWindow() // Ensure that we have a default size, otherwise an empty window statement will // result in no window resize(QSize(100, 100)); + _view->setBackgroundBrush(palette().window()); setCentralWidget(_view); setAttribute(Qt::WA_DeleteOnClose); } diff --git a/src/qwindowitem.cpp b/src/qwindowitem.cpp index b57393d68e7d838adfaf8c409ee9b35870dfb3cb..a97aa1cf1695a8c34fea6b34ce9dcc68aebbadd3 100644 --- a/src/qwindowitem.cpp +++ b/src/qwindowitem.cpp @@ -46,11 +46,13 @@ QWindowItem::QWindowItem(QTopLevelWindow* tlw) : _window(tlw ? tlw : new QTopLevelWindow), _positionIsDefined(false), _delayedVisible(false) { - connect(_window, SIGNAL(visibilityChanged()), this, SIGNAL(visibilityChanged())); + connect(_window, SIGNAL(visibilityChanged()), this, SIGNAL(visibleChanged())); connect(_window, SIGNAL(windowStateChanged()), this, SIGNAL(windowStateChanged())); connect(_window, SIGNAL(sizeChanged(QSize)), this, SLOT(updateSize(QSize))); + connect(qApp, SIGNAL(aboutToQuit()), _window, SLOT(close())); view()->setResizeMode(QDeclarativeView::SizeRootObjectToView); + _window->installEventFilter(this); } QWindowItem::~QWindowItem() @@ -60,14 +62,19 @@ QWindowItem::~QWindowItem() bool QWindowItem::eventFilter(QObject *, QEvent *ev) { switch(ev->type()) { - case QEvent::Resize: - emit sizeChanged(); - break; - case QEvent::Move: - emit positionChanged(); - break; - default: - break; + case QEvent::Resize: + emit sizeChanged(); + emit widthChanged(); + emit heightChanged(); + break; + + case QEvent::Move: + emit xChanged(); + emit yChanged(); + break; + + default: + break; } return false; } @@ -107,6 +114,11 @@ void QWindowItem::updateSize(QSize newSize) emit sizeChanged(); } +void QWindowItem::center() +{ + _window->center(); +} + void QWindowItem::setX(int x) { _window->move(x, y()); @@ -170,7 +182,7 @@ void QWindowItem::setWindowDecoration(bool s) { bool visible = _window->isVisible(); _window->setWindowFlags(s ? _window->windowFlags() & ~Qt::FramelessWindowHint - : _window->windowFlags() | Qt::FramelessWindowHint); + : _window->windowFlags() | Qt::FramelessWindowHint); if (visible) _window->show(); emit windowDecorationChanged(); diff --git a/src/qwindowitem.h b/src/qwindowitem.h index d444e6a64467c104ed44ef3c7483aefdf70b2db5..50c41b02febdf05a584f5a0250ff16e6e7d187c0 100644 --- a/src/qwindowitem.h +++ b/src/qwindowitem.h @@ -38,15 +38,15 @@ class QWindowItem : public QDeclarativeItem { Q_OBJECT - Q_PROPERTY(int x READ x WRITE setX NOTIFY positionChanged) - Q_PROPERTY(int y READ y WRITE setY NOTIFY positionChanged) + Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged) + Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged) Q_PROPERTY(int height READ height WRITE setHeight NOTIFY sizeChanged) Q_PROPERTY(int width READ width WRITE setWidth NOTIFY sizeChanged) Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged) Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged) Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged) Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged) - Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibilityChanged) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(bool windowDecoration READ windowDecoration WRITE setWindowDecoration NOTIFY windowDecorationChanged) Q_PROPERTY(bool modal READ modal WRITE setModal NOTIFY modalityChanged) Q_PROPERTY(bool close READ close WRITE setClose) @@ -97,11 +97,13 @@ protected: protected Q_SLOTS: void updateSize(QSize newSize); + void center(); Q_SIGNALS: void sizeChanged(); - void positionChanged(); - void visibilityChanged(); + void xChanged(); + void yChanged(); + void visibleChanged(); void windowDecorationChanged(); void windowStateChanged(); void minimumHeightChanged();