source: trunk/examples/dialogs/tabdialog/tabdialog.cpp@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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