~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to examples/widgets/dialogs/tabdialog/tabdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
#include <QtWidgets>
 
42
 
 
43
#include "tabdialog.h"
 
44
 
 
45
//! [0]
 
46
TabDialog::TabDialog(const QString &fileName, QWidget *parent)
 
47
    : QDialog(parent)
 
48
{
 
49
    QFileInfo fileInfo(fileName);
 
50
 
 
51
    tabWidget = new QTabWidget;
 
52
    tabWidget->addTab(new GeneralTab(fileInfo), tr("General"));
 
53
    tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions"));
 
54
    tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));
 
55
//! [0]
 
56
 
 
57
//! [1] //! [2]
 
58
    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
 
59
//! [1] //! [3]
 
60
                                     | QDialogButtonBox::Cancel);
 
61
 
 
62
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
 
63
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
 
64
//! [2] //! [3]
 
65
 
 
66
//! [4]
 
67
    QVBoxLayout *mainLayout = new QVBoxLayout;
 
68
    mainLayout->setSizeConstraint(QLayout::SetNoConstraint);
 
69
    mainLayout->addWidget(tabWidget);
 
70
    mainLayout->addWidget(buttonBox);
 
71
    setLayout(mainLayout);
 
72
//! [4]
 
73
 
 
74
//! [5]
 
75
    setWindowTitle(tr("Tab Dialog"));
 
76
}
 
77
//! [5]
 
78
 
 
79
//! [6]
 
80
GeneralTab::GeneralTab(const QFileInfo &fileInfo, QWidget *parent)
 
81
    : QWidget(parent)
 
82
{
 
83
    QLabel *fileNameLabel = new QLabel(tr("File Name:"));
 
84
    QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName());
 
85
 
 
86
    QLabel *pathLabel = new QLabel(tr("Path:"));
 
87
    QLabel *pathValueLabel = new QLabel(fileInfo.absoluteFilePath());
 
88
    pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
89
 
 
90
    QLabel *sizeLabel = new QLabel(tr("Size:"));
 
91
    qlonglong size = fileInfo.size()/1024;
 
92
    QLabel *sizeValueLabel = new QLabel(tr("%1 K").arg(size));
 
93
    sizeValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
94
 
 
95
    QLabel *lastReadLabel = new QLabel(tr("Last Read:"));
 
96
    QLabel *lastReadValueLabel = new QLabel(fileInfo.lastRead().toString());
 
97
    lastReadValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
98
 
 
99
    QLabel *lastModLabel = new QLabel(tr("Last Modified:"));
 
100
    QLabel *lastModValueLabel = new QLabel(fileInfo.lastModified().toString());
 
101
    lastModValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
102
 
 
103
    QVBoxLayout *mainLayout = new QVBoxLayout;
 
104
    mainLayout->addWidget(fileNameLabel);
 
105
    mainLayout->addWidget(fileNameEdit);
 
106
    mainLayout->addWidget(pathLabel);
 
107
    mainLayout->addWidget(pathValueLabel);
 
108
    mainLayout->addWidget(sizeLabel);
 
109
    mainLayout->addWidget(sizeValueLabel);
 
110
    mainLayout->addWidget(lastReadLabel);
 
111
    mainLayout->addWidget(lastReadValueLabel);
 
112
    mainLayout->addWidget(lastModLabel);
 
113
    mainLayout->addWidget(lastModValueLabel);
 
114
    mainLayout->addStretch(1);
 
115
    setLayout(mainLayout);
 
116
}
 
117
//! [6]
 
118
 
 
119
//! [7]
 
120
PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent)
 
121
    : QWidget(parent)
 
122
{
 
123
    QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions"));
 
124
 
 
125
    QCheckBox *readable = new QCheckBox(tr("Readable"));
 
126
    if (fileInfo.isReadable())
 
127
        readable->setChecked(true);
 
128
 
 
129
    QCheckBox *writable = new QCheckBox(tr("Writable"));
 
130
    if ( fileInfo.isWritable() )
 
131
        writable->setChecked(true);
 
132
 
 
133
    QCheckBox *executable = new QCheckBox(tr("Executable"));
 
134
    if ( fileInfo.isExecutable() )
 
135
        executable->setChecked(true);
 
136
 
 
137
    QGroupBox *ownerGroup = new QGroupBox(tr("Ownership"));
 
138
 
 
139
    QLabel *ownerLabel = new QLabel(tr("Owner"));
 
140
    QLabel *ownerValueLabel = new QLabel(fileInfo.owner());
 
141
    ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
142
 
 
143
    QLabel *groupLabel = new QLabel(tr("Group"));
 
144
    QLabel *groupValueLabel = new QLabel(fileInfo.group());
 
145
    groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
 
146
 
 
147
    QVBoxLayout *permissionsLayout = new QVBoxLayout;
 
148
    permissionsLayout->addWidget(readable);
 
149
    permissionsLayout->addWidget(writable);
 
150
    permissionsLayout->addWidget(executable);
 
151
    permissionsGroup->setLayout(permissionsLayout);
 
152
 
 
153
    QVBoxLayout *ownerLayout = new QVBoxLayout;
 
154
    ownerLayout->addWidget(ownerLabel);
 
155
    ownerLayout->addWidget(ownerValueLabel);
 
156
    ownerLayout->addWidget(groupLabel);
 
157
    ownerLayout->addWidget(groupValueLabel);
 
158
    ownerGroup->setLayout(ownerLayout);
 
159
 
 
160
    QVBoxLayout *mainLayout = new QVBoxLayout;
 
161
    mainLayout->addWidget(permissionsGroup);
 
162
    mainLayout->addWidget(ownerGroup);
 
163
    mainLayout->addStretch(1);
 
164
    setLayout(mainLayout);
 
165
}
 
166
//! [7]
 
167
 
 
168
//! [8]
 
169
ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent)
 
170
    : QWidget(parent)
 
171
{
 
172
    QLabel *topLabel = new QLabel(tr("Open with:"));
 
173
 
 
174
    QListWidget *applicationsListBox = new QListWidget;
 
175
    QStringList applications;
 
176
 
 
177
    for (int i = 1; i <= 30; ++i)
 
178
        applications.append(tr("Application %1").arg(i));
 
179
    applicationsListBox->insertItems(0, applications);
 
180
 
 
181
    QCheckBox *alwaysCheckBox;
 
182
 
 
183
    if (fileInfo.suffix().isEmpty())
 
184
        alwaysCheckBox = new QCheckBox(tr("Always use this application to "
 
185
            "open this type of file"));
 
186
    else
 
187
        alwaysCheckBox = new QCheckBox(tr("Always use this application to "
 
188
            "open files with the extension '%1'").arg(fileInfo.suffix()));
 
189
 
 
190
    QVBoxLayout *layout = new QVBoxLayout;
 
191
    layout->addWidget(topLabel);
 
192
    layout->addWidget(applicationsListBox);
 
193
    layout->addWidget(alwaysCheckBox);
 
194
    setLayout(layout);
 
195
}
 
196
//! [8]