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

source code of qtbase/examples/widgets/dialogs/tabdialog/tabdialog.cpp