diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2012-12-29 22:48:27 -0500 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-01-02 09:29:40 +0100 |
commit | 2d3c5f1083b2c84a90a870449a66355750621817 (patch) | |
tree | 62e9fe76fccc849c5440c4eaf32ea9d81857b7ff /examples | |
parent | f12edbc081ba1e1cbe12bf540619fb0fa17fff62 (diff) |
Add more functionality to QtMacUnifiedToolBar.
Getters and setters are now provided for:
* Toolbar visibility
* Baseline separator visibility
* Whether to allow user customization menu
* Button style (icon only, text and icon, etc.)
* Icon size (small or regular)
Added QSize getters and setters for the iconSize property for
compatibility with the QToolBar API.
Added signals to react to changes to any of these properties, which
will also be emitted when the properties are changed through
native Cocoa code, not just the QtMacUnifiedToolbar API. This
allows the application to respond to the user right clicking
the toolbar and changing button style, visibility, etc., from
there.
The example app now includes a bunch of controls to manipulate
the toolbar's properties so users can visually explore the
capabilities of the API.
Change-Id: I2fd8b9d84fd4f981675eccc48f275e11524c6875
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/macunifiedtoolbar/macunifiedtoolbar.pro | 10 | ||||
-rw-r--r-- | examples/macunifiedtoolbar/main.cpp | 23 | ||||
-rw-r--r-- | examples/macunifiedtoolbar/window.cpp | 129 | ||||
-rw-r--r-- | examples/macunifiedtoolbar/window.h | 75 | ||||
-rw-r--r-- | examples/macunifiedtoolbar/window.ui | 151 |
5 files changed, 367 insertions, 21 deletions
diff --git a/examples/macunifiedtoolbar/macunifiedtoolbar.pro b/examples/macunifiedtoolbar/macunifiedtoolbar.pro index b6be400..a780f68 100644 --- a/examples/macunifiedtoolbar/macunifiedtoolbar.pro +++ b/examples/macunifiedtoolbar/macunifiedtoolbar.pro @@ -2,9 +2,17 @@ include (../../src/qtmacextras.pri) QT += widgets -SOURCES += main.cpp +SOURCES += main.cpp \ + window.cpp RESOURCES += \ macunifiedtoolbar.qrc ICON = qtlogo.icns + +HEADERS += \ + window.h + +FORMS += \ + window.ui + diff --git a/examples/macunifiedtoolbar/main.cpp b/examples/macunifiedtoolbar/main.cpp index 417792a..4124c35 100644 --- a/examples/macunifiedtoolbar/main.cpp +++ b/examples/macunifiedtoolbar/main.cpp @@ -39,31 +39,14 @@ ** ****************************************************************************/ -#include "qtmacunifiedtoolbar.h" #include <QApplication> -#include <QWidget> +#include "window.h" int main(int argc, char **argv) { QApplication app(argc, argv); - - QWidget widget; - widget.resize(300, 300); - widget.setWindowTitle("Qt Mac Toolbar Example"); - - QtMacUnifiedToolBar toolBar; - toolBar.addAction(QIcon(":/qtlogo.png"), "Hello"); - toolBar.addAction(QIcon(":/qtlogo.png"), "World"); - toolBar.addStandardItem(QtMacToolButton::FlexibleSpace); - toolBar.addStandardItem(QtMacToolButton::ShowColors); - toolBar.addStandardItem(QtMacToolButton::ShowFonts); - - toolBar.addAllowedAction(QIcon(":/qtlogo.png"), "Extra Button 1"); - toolBar.addAllowedAction(QIcon(":/qtlogo.png"), "Extra Button 2"); - - toolBar.showInWindowForWidget(&widget); - widget.show(); - + Window window; + window.show(); return app.exec(); } diff --git a/examples/macunifiedtoolbar/window.cpp b/examples/macunifiedtoolbar/window.cpp new file mode 100644 index 0000000..8fd00bc --- /dev/null +++ b/examples/macunifiedtoolbar/window.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** + ** + ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). + ** Contact: http://www.qt-project.org/legal + ** + ** This file is part of QtMacExtras in the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** 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. + ** + ** GNU Lesser General Public License Usage + ** 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. + ** + ** In addition, as a special exception, Digia gives you certain additional + ** rights. These rights are described in the Digia Qt LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3.0 as published by the Free Software + ** Foundation and appearing in the file LICENSE.GPL included in the + ** packaging of this file. Please review the following information to + ** ensure the GNU General Public License version 3.0 requirements will be + ** met: http://www.gnu.org/copyleft/gpl.html. + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include "window.h" +#include "ui_window.h" +#include "qtmacunifiedtoolbar.h" +#include <QDesktopWidget> +#include <QTimer> + +class WindowPrivate +{ +public: + QtMacUnifiedToolBar *toolBar; +}; + +Window::Window(QWidget *parent) : + QWidget(parent), + d(new WindowPrivate), + ui(new Ui::Window) +{ + ui->setupUi(this); + + d->toolBar = new QtMacUnifiedToolBar(this); + d->toolBar->addAction(QIcon(":/qtlogo.png"), "Hello"); + d->toolBar->addAction(QIcon(":/qtlogo.png"), "World"); + d->toolBar->addStandardItem(QtMacToolButton::FlexibleSpace); + d->toolBar->addStandardItem(QtMacToolButton::ShowColors); + d->toolBar->addStandardItem(QtMacToolButton::ShowFonts); + d->toolBar->addStandardItem(QtMacToolButton::PrintItem); + + d->toolBar->addAllowedAction(QIcon(":/qtlogo.png"), "Extra Button 1"); + d->toolBar->addAllowedAction(QIcon(":/qtlogo.png"), "Extra Button 2"); + + d->toolBar->showInWindowForWidget(this); + + connect(d->toolBar, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), SLOT(displayModeChanged(Qt::ToolButtonStyle))); + ui->displayModeComboBox->setCurrentIndex(d->toolBar->toolButtonStyle()); + + connect(d->toolBar, SIGNAL(iconSizeChanged(QtMacToolButton::IconSize)), SLOT(sizeModeChanged(QtMacToolButton::IconSize))); + ui->sizeModeComboBox->setCurrentIndex(d->toolBar->iconSizeType()); + + connect(ui->visibleCheckBox, SIGNAL(clicked(bool)), d->toolBar, SLOT(setVisible(bool))); + connect(d->toolBar, SIGNAL(visibilityChanged(bool)), ui->visibleCheckBox, SLOT(setChecked(bool))); + ui->visibleCheckBox->setChecked(d->toolBar->isVisible()); + + connect(ui->showsBaselineSeparatorCheckBox, SIGNAL(clicked(bool)), d->toolBar, SLOT(setShowsBaselineSeparator(bool))); + connect(d->toolBar, SIGNAL(showsBaselineSeparatorChanged(bool)), ui->showsBaselineSeparatorCheckBox, SLOT(setChecked(bool))); + ui->showsBaselineSeparatorCheckBox->setChecked(d->toolBar->showsBaselineSeparator()); + + connect(ui->allowsUserCustomizationCheckBox, SIGNAL(clicked(bool)), d->toolBar, SLOT(setAllowsUserCustomization(bool))); + connect(d->toolBar, SIGNAL(allowsUserCustomizationChanged(bool)), ui->allowsUserCustomizationCheckBox, SLOT(setChecked(bool))); + ui->allowsUserCustomizationCheckBox->setChecked(d->toolBar->allowsUserCustomization()); + + connect(ui->showCustomizationSheetPushButton, SIGNAL(clicked()), d->toolBar, SLOT(showCustomizationSheet())); + connect(d->toolBar, SIGNAL(allowsUserCustomizationChanged(bool)), ui->showCustomizationSheetPushButton, SLOT(setEnabled(bool))); + ui->showCustomizationSheetPushButton->setEnabled(d->toolBar->allowsUserCustomization()); + + QTimer::singleShot(0, this, SLOT(positionWindow())); +} + +Window::~Window() +{ + delete ui; + delete d; +} + +void Window::changeDisplayMode(int toolButtonStyle) +{ + d->toolBar->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(toolButtonStyle)); +} + +void Window::displayModeChanged(Qt::ToolButtonStyle toolButtonStyle) +{ + ui->displayModeComboBox->setCurrentIndex(toolButtonStyle); +} + +void Window::changeSizeMode(int sizeMode) +{ + d->toolBar->setIconSize(static_cast<QtMacToolButton::IconSize>(sizeMode)); +} + +void Window::sizeModeChanged(QtMacToolButton::IconSize size) +{ + ui->sizeModeComboBox->setCurrentIndex(size); +} + +void Window::positionWindow() +{ + resize(QSize()); + setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, size(), qApp->desktop()->availableGeometry())); +} diff --git a/examples/macunifiedtoolbar/window.h b/examples/macunifiedtoolbar/window.h new file mode 100644 index 0000000..39ac28c --- /dev/null +++ b/examples/macunifiedtoolbar/window.h @@ -0,0 +1,75 @@ +/**************************************************************************** + ** + ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). + ** Contact: http://www.qt-project.org/legal + ** + ** This file is part of QtMacExtras in the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** 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. + ** + ** GNU Lesser General Public License Usage + ** 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. + ** + ** In addition, as a special exception, Digia gives you certain additional + ** rights. These rights are described in the Digia Qt LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3.0 as published by the Free Software + ** Foundation and appearing in the file LICENSE.GPL included in the + ** packaging of this file. Please review the following information to + ** ensure the GNU General Public License version 3.0 requirements will be + ** met: http://www.gnu.org/copyleft/gpl.html. + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> +#include "qtmactoolbutton.h" + +namespace Ui { +class Window; +} + +class WindowPrivate; +class Window : public QWidget +{ + Q_OBJECT + +public: + explicit Window(QWidget *parent = 0); + ~Window(); + +private slots: + void changeDisplayMode(int); + void displayModeChanged(Qt::ToolButtonStyle); + + void changeSizeMode(int); + void sizeModeChanged(QtMacToolButton::IconSize); + + void positionWindow(); + +private: + WindowPrivate *d; + Ui::Window *ui; +}; + +#endif // WINDOW_H diff --git a/examples/macunifiedtoolbar/window.ui b/examples/macunifiedtoolbar/window.ui new file mode 100644 index 0000000..90081a0 --- /dev/null +++ b/examples/macunifiedtoolbar/window.ui @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Window</class> + <widget class="QWidget" name="Window"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>265</width> + <height>173</height> + </rect> + </property> + <property name="windowTitle"> + <string>Qt Mac Toolbar Example</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::FieldsStayAtSizeHint</enum> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="displayModeLabel"> + <property name="text"> + <string>Display mode:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="displayModeComboBox"> + <item> + <property name="text"> + <string>IconOnly</string> + </property> + </item> + <item> + <property name="text"> + <string>TextOnly</string> + </property> + </item> + <item> + <property name="text"> + <string>TextBesideIcon</string> + </property> + </item> + <item> + <property name="text"> + <string>TextUnderIcon</string> + </property> + </item> + <item> + <property name="text"> + <string>FollowStyle</string> + </property> + </item> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="sizeModeLabel"> + <property name="text"> + <string>Size mode:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="sizeModeComboBox"> + <item> + <property name="text"> + <string>Default</string> + </property> + </item> + <item> + <property name="text"> + <string>Regular</string> + </property> + </item> + <item> + <property name="text"> + <string>Small</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QCheckBox" name="visibleCheckBox"> + <property name="text"> + <string>Visible</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QCheckBox" name="showsBaselineSeparatorCheckBox"> + <property name="text"> + <string>Shows baseline separator</string> + </property> + </widget> + </item> + <item row="4" column="0" colspan="2"> + <widget class="QCheckBox" name="allowsUserCustomizationCheckBox"> + <property name="text"> + <string>Allows user customization</string> + </property> + </widget> + </item> + <item row="5" column="0" colspan="2"> + <widget class="QPushButton" name="showCustomizationSheetPushButton"> + <property name="text"> + <string>Show customization sheet</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>displayModeComboBox</sender> + <signal>currentIndexChanged(int)</signal> + <receiver>Window</receiver> + <slot>changeDisplayMode(int)</slot> + <hints> + <hint type="sourcelabel"> + <x>337</x> + <y>22</y> + </hint> + <hint type="destinationlabel"> + <x>288</x> + <y>149</y> + </hint> + </hints> + </connection> + <connection> + <sender>sizeModeComboBox</sender> + <signal>currentIndexChanged(int)</signal> + <receiver>Window</receiver> + <slot>changeSizeMode(int)</slot> + <hints> + <hint type="sourcelabel"> + <x>158</x> + <y>52</y> + </hint> + <hint type="destinationlabel"> + <x>132</x> + <y>86</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>changeDisplayMode(int)</slot> + <slot>changeSizeMode(int)</slot> + </slots> +</ui> |