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

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

trunk: Merged in qt 4.6.2 sources.

File size: 6.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43
44#include "tabdialog.h"
45
46//! [0]
47TabDialog::TabDialog(const QString &fileName, QWidget *parent)
48 : QDialog(parent)
49{
50 QFileInfo fileInfo(fileName);
51
52 tabWidget = new QTabWidget;
53 tabWidget->addTab(new GeneralTab(fileInfo), tr("General"));
54 tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions"));
55 tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));
56//! [0]
57
58//! [1] //! [2]
59 buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
60//! [1] //! [3]
61 | QDialogButtonBox::Cancel);
62
63 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
64 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
65//! [2] //! [3]
66
67//! [4]
68 QVBoxLayout *mainLayout = new QVBoxLayout;
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]
80GeneralTab::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]
120PermissionsTab::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]
169ApplicationsTab::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]
Note: See TracBrowser for help on using the repository browser.