summaryrefslogtreecommitdiffstats
path: root/examples/testapp
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-05-16 22:39:08 +0200
committerkh1 <qt-info@nokia.com>2011-05-16 22:39:08 +0200
commita7d5b972bdc97cef4ff7e102a2c76e7bda3b4833 (patch)
tree43fd3f87b21521e590abcc010c2baffd9f1337e0 /examples/testapp
parent5e31e24f2403e5b31d5e288fdd1f13e2e1154881 (diff)
Move to the only place where it's still used.
Diffstat (limited to 'examples/testapp')
-rw-r--r--examples/testapp/componentselectiondialog.cpp210
-rw-r--r--examples/testapp/componentselectiondialog.h67
-rw-r--r--examples/testapp/componentselectiondialog.ui182
3 files changed, 459 insertions, 0 deletions
diff --git a/examples/testapp/componentselectiondialog.cpp b/examples/testapp/componentselectiondialog.cpp
new file mode 100644
index 000000000..a45524ee0
--- /dev/null
+++ b/examples/testapp/componentselectiondialog.cpp
@@ -0,0 +1,210 @@
+/**************************************************************************
+**
+** This file is part of Qt SDK**
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).*
+**
+** Contact: Nokia Corporation qt-info@nokia.com**
+**
+** No Commercial Usage
+**
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception version
+** 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you are unsure which license is appropriate for your use, please contact
+** (qt-info@nokia.com).
+**
+**************************************************************************/
+#include "componentselectiondialog.h"
+#include "ui_componentselectiondialog.h"
+
+#include <QPushButton>
+#include <QHeaderView>
+
+#include "qinstaller.h"
+#include "qinstallercomponent.h"
+#include "qinstallercomponentmodel.h"
+
+using namespace QInstaller;
+
+class ComponentSelectionDialog::Private : public QObject
+{
+ Q_OBJECT
+public:
+ Private( ComponentSelectionDialog* qq, Installer* inst )
+ : q( qq ),
+ installer( inst )
+ {
+ }
+
+ void selectionChanged()
+ {
+ // no component selected disables the ok button
+ const QList< Component* > components = installer->components( true, UpdaterMode );
+ int selectionCount = 0;
+ for( QList< Component* >::const_iterator it = components.begin(); it != components.end(); ++it )
+ {
+ if( (*it)->isSelected( UpdaterMode ) )
+ ++selectionCount;
+ }
+
+ installBtn->setEnabled( selectionCount > 0 );
+ installBtn->setText( selectionCount > 1 ? tr( "Install %1 Items" ).arg( selectionCount ) :
+ selectionCount == 1 ? tr( "Install 1 Item" ) : tr( "Install" ) );
+
+ if (selectionCount > 0) {
+ ui.buttonBox->button( QDialogButtonBox::Cancel )->setText(tr("Cancel"));
+ } else {
+ ui.buttonBox->button( QDialogButtonBox::Cancel )->setText(tr("Close"));
+ }
+
+ const QModelIndex index = ui.treeView->currentIndex();
+ if( !index.isValid() )
+ {
+ ui.textBrowser->clear();
+ return;
+ }
+
+ ui.textBrowser->setHtml( index.sibling( index.row(), 0 ).data( Qt::ToolTipRole ).toString() );
+ }
+
+ void modelReset()
+ {
+ ui.treeView->header()->resizeSection( 0, ui.labelTitle->sizeHint().width() / 1.5 );
+ ui.treeView->header()->setStretchLastSection( true );
+ for ( int i = 0; i < ui.treeView->model()->columnCount(); ++i )
+ ui.treeView->resizeColumnToContents( i );
+
+ bool hasChildren = false;
+ const int rowCount = ui.treeView->model()->rowCount();
+ for( int row = 0; row < rowCount && !hasChildren; ++row )
+ hasChildren = ui.treeView->model()->hasChildren( ui.treeView->model()->index( row, 0 ) );
+ ui.treeView->setRootIsDecorated( hasChildren );
+ ui.treeView->expandToDepth( 0 );
+ selectionChanged();
+ }
+
+private:
+ ComponentSelectionDialog* const q;
+
+public:
+ Ui::ComponentSelectionDialog ui;
+ Installer* const installer;
+ ComponentModel* componentModel;
+ QPushButton* installBtn;
+
+public Q_SLOTS:
+ void selectAll();
+ void deselectAll();
+};
+
+void ComponentSelectionDialog::Private::selectAll()
+{
+ QList< Component* > updaterComponents = installer->components( false, UpdaterMode );
+ Q_FOREACH( Component* comp, updaterComponents )
+ {
+ comp->setSelected( true, UpdaterMode );
+ }
+}
+
+void ComponentSelectionDialog::Private::deselectAll()
+{
+ QList< Component* > updaterComponents = installer->components( false, UpdaterMode );
+ Q_FOREACH( Component* comp, updaterComponents )
+ {
+ comp->setSelected( false, UpdaterMode );
+ }
+}
+
+void ComponentSelectionDialog::refreshDialog()
+{
+ d->selectionChanged();
+}
+
+ComponentSelectionDialog::ComponentSelectionDialog( Installer* installer, QWidget* parent )
+ : QDialog( parent ),
+ d( new Private( this, installer ) )
+{
+ d->ui.setupUi( this );
+ d->componentModel = new ComponentModel( installer, UpdaterMode );
+ d->ui.treeView->setModel( d->componentModel );
+
+ d->ui.labelLicenseBlurb->setAttribute( Qt::WA_MacSmallSize );
+ d->ui.labelSubTitle->setAttribute( Qt::WA_MacSmallSize );
+ d->ui.treeView->setAttribute( Qt::WA_MacShowFocusRect, false );
+ d->ui.textBrowser->setAttribute( Qt::WA_MacShowFocusRect, false );
+ d->ui.splitter->setCollapsible( 0, false );
+ d->installBtn = d->ui.buttonBox->addButton( tr( "Install" ), QDialogButtonBox::AcceptRole ) ;
+ if ( !d->ui.buttonBox->button( QDialogButtonBox::Cancel )->icon().isNull() )
+ d->installBtn->setIcon( style()->standardIcon( QStyle::SP_DialogOkButton ) );
+
+ d->ui.icon->setPixmap( windowIcon().pixmap( 48, 48 ) );
+
+ connect( d->ui.treeView->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
+ this, SLOT( selectionChanged() ) );
+ connect( d->ui.treeView->model(), SIGNAL( modelReset() ),
+ this, SLOT( modelReset() ) );
+ connect( d->ui.treeView->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ),
+ this, SLOT( selectionChanged() ) );
+ connect( d->installBtn, SIGNAL( clicked() ), this, SIGNAL( requestUpdate() ) );
+ connect( d->ui.selectAll, SIGNAL( clicked() ), d.get(), SLOT( selectAll() ), Qt::QueuedConnection );
+ connect( d->ui.deselectAll, SIGNAL( clicked() ), d.get(), SLOT( deselectAll() ), Qt::QueuedConnection );
+
+
+ d->ui.treeView->setCurrentIndex( d->ui.treeView->model()->index( 0, 0 ) );
+ d->ui.splitter->setStretchFactor( 0, 2 );
+ d->ui.splitter->setStretchFactor( 1, 1 );
+ d->ui.treeView->header()->setStretchLastSection( true );
+ for ( int i = 0; i < d->ui.treeView->model()->columnCount(); ++i )
+ d->ui.treeView->resizeColumnToContents( i );
+ d->selectionChanged();
+ d->modelReset();
+}
+
+ComponentSelectionDialog::~ComponentSelectionDialog()
+{
+}
+
+void ComponentSelectionDialog::selectAll() {
+ d->selectAll();
+}
+
+void ComponentSelectionDialog::deselectAll() {
+ d->deselectAll();
+}
+
+void ComponentSelectionDialog::install() {
+ emit requestUpdate();
+}
+
+void ComponentSelectionDialog::selectComponent( const QString& id ) {
+ const QModelIndex idx = d->componentModel->findComponent( id );
+ if ( !idx.isValid() )
+ return;
+ d->componentModel->setData( idx, Qt::Checked );
+}
+
+void ComponentSelectionDialog::deselectComponent( const QString& id ) {
+ const QModelIndex idx = d->componentModel->findComponent( id );
+ if ( !idx.isValid() )
+ return;
+ d->componentModel->setData( idx, Qt::Unchecked );
+}
+
+#include "moc_componentselectiondialog.cpp"
+#include "componentselectiondialog.moc"
diff --git a/examples/testapp/componentselectiondialog.h b/examples/testapp/componentselectiondialog.h
new file mode 100644
index 000000000..0b67084c6
--- /dev/null
+++ b/examples/testapp/componentselectiondialog.h
@@ -0,0 +1,67 @@
+/**************************************************************************
+**
+** This file is part of Qt SDK**
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).*
+**
+** Contact: Nokia Corporation qt-info@nokia.com**
+**
+** GNU Lesser General Public License Usage
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception version
+** 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you are unsure which license is appropriate for your use, please contact
+** (qt-info@nokia.com).
+**
+**************************************************************************/
+#ifndef COMPONENTSELECTIONDIALOG_H
+#define COMPONENTSELECTIONDIALOG_H
+
+#include <QtGui/QDialog>
+
+#include <KDToolsCore/pimpl_ptr>
+
+#include "installer_global.h"
+
+namespace QInstaller
+{
+class Installer;
+
+class INSTALLER_EXPORT ComponentSelectionDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit ComponentSelectionDialog( QInstaller::Installer* installer, QWidget* parent = 0 );
+ ~ComponentSelectionDialog();
+ Q_INVOKABLE void selectComponent( const QString& compoenent );
+ Q_INVOKABLE void deselectComponent( const QString& component );
+ Q_INVOKABLE void selectAll();
+ Q_INVOKABLE void deselectAll();
+ Q_INVOKABLE void install();
+
+public Q_SLOTS:
+ void refreshDialog();
+
+Q_SIGNALS:
+ void requestUpdate();
+
+private:
+ Q_PRIVATE_SLOT( d, void selectionChanged() );
+ Q_PRIVATE_SLOT( d, void modelReset() );
+
+ class Private;
+ kdtools::pimpl_ptr< Private > d;
+};
+
+}
+
+#endif
diff --git a/examples/testapp/componentselectiondialog.ui b/examples/testapp/componentselectiondialog.ui
new file mode 100644
index 000000000..a161612ac
--- /dev/null
+++ b/examples/testapp/componentselectiondialog.ui
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ComponentSelectionDialog</class>
+ <widget class="QDialog" name="ComponentSelectionDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>656</width>
+ <height>406</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Software Update</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" rowspan="3">
+ <widget class="QLabel" name="icon">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="pixmap">
+ <pixmap>:/logo.png</pixmap>
+ </property>
+ <property name="scaledContents">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="labelTitle">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>All available updates are shown below.</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" rowspan="2">
+ <widget class="QLabel" name="labelSubTitle">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Installing this software may take some time. If you're not ready to install now, you can choose Software Update from the menu later.</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QTreeView" name="treeView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ <widget class="QTextBrowser" name="textBrowser">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
+ <item>
+ <widget class="QPushButton" name="selectAll">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>SelectAll</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deselectAll">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Deselect All</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QLabel" name="labelLicenseBlurb">
+ <property name="text">
+ <string>Note: Use of this software is subject to the original Software License Agreement(s) that accompanied the software being updated.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ComponentSelectionDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>