1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the examples of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui>
|
---|
43 |
|
---|
44 | #include "tabdialog.h"
|
---|
45 |
|
---|
46 | //! [0]
|
---|
47 | TabDialog::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]
|
---|
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]
|
---|
|
---|