tabdialog.cpp Example File | Qt 4.8 (original) (raw)
dialogs/tabdialog/tabdialog.cpp
#include
#include "tabdialog.h"
TabDialog::TabDialog(const QString &fileName, QWidget *parent) : QDialog(parent) { QFileInfo fileInfo(fileName);
tabWidget = new [QTabWidget](qtabwidget.html);
tabWidget->addTab(new GeneralTab(fileInfo), tr("General"));
tabWidget->addTab(new PermissionsTab(fileInfo), tr("Permissions"));
tabWidget->addTab(new ApplicationsTab(fileInfo), tr("Applications"));
buttonBox = new [QDialogButtonBox](qdialogbuttonbox.html)([QDialogButtonBox](qdialogbuttonbox.html)::Ok
| [QDialogButtonBox](qdialogbuttonbox.html)::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
[QVBoxLayout](qvboxlayout.html) *mainLayout = new [QVBoxLayout](qvboxlayout.html);
mainLayout->setSizeConstraint([QLayout](qlayout.html)::SetNoConstraint);
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Tab Dialog"));}
GeneralTab::GeneralTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QLabel *fileNameLabel = new QLabel(tr("File Name:")); QLineEdit *fileNameEdit = new QLineEdit(fileInfo.fileName());
[QLabel](qlabel.html) *pathLabel = new [QLabel](qlabel.html)(tr("Path:"));
[QLabel](qlabel.html) *pathValueLabel = new [QLabel](qlabel.html)(fileInfo.absoluteFilePath());
pathValueLabel->setFrameStyle([QFrame](qframe.html)::Panel | [QFrame](qframe.html)::Sunken);
[QLabel](qlabel.html) *sizeLabel = new [QLabel](qlabel.html)(tr("Size:"));
[qlonglong](qtglobal.html#qlonglong-typedef) size = fileInfo.size()/1024;
[QLabel](qlabel.html) *sizeValueLabel = new [QLabel](qlabel.html)(tr("%1 K").arg(size));
sizeValueLabel->setFrameStyle([QFrame](qframe.html)::Panel | [QFrame](qframe.html)::Sunken);
[QLabel](qlabel.html) *lastReadLabel = new [QLabel](qlabel.html)(tr("Last Read:"));
[QLabel](qlabel.html) *lastReadValueLabel = new [QLabel](qlabel.html)(fileInfo.lastRead().toString());
lastReadValueLabel->setFrameStyle([QFrame](qframe.html)::Panel | [QFrame](qframe.html)::Sunken);
[QLabel](qlabel.html) *lastModLabel = new [QLabel](qlabel.html)(tr("Last Modified:"));
[QLabel](qlabel.html) *lastModValueLabel = new [QLabel](qlabel.html)(fileInfo.lastModified().toString());
lastModValueLabel->setFrameStyle([QFrame](qframe.html)::Panel | [QFrame](qframe.html)::Sunken);
[QVBoxLayout](qvboxlayout.html) *mainLayout = new [QVBoxLayout](qvboxlayout.html);
mainLayout->addWidget(fileNameLabel);
mainLayout->addWidget(fileNameEdit);
mainLayout->addWidget(pathLabel);
mainLayout->addWidget(pathValueLabel);
mainLayout->addWidget(sizeLabel);
mainLayout->addWidget(sizeValueLabel);
mainLayout->addWidget(lastReadLabel);
mainLayout->addWidget(lastReadValueLabel);
mainLayout->addWidget(lastModLabel);
mainLayout->addWidget(lastModValueLabel);
mainLayout->addStretch(1);
setLayout(mainLayout);}
PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions"));
[QCheckBox](qcheckbox.html) *readable = new [QCheckBox](qcheckbox.html)(tr("Readable"));
if (fileInfo.isReadable())
readable->setChecked(true);
[QCheckBox](qcheckbox.html) *writable = new [QCheckBox](qcheckbox.html)(tr("Writable"));
if ( fileInfo.isWritable() )
writable->setChecked(true);
[QCheckBox](qcheckbox.html) *executable = new [QCheckBox](qcheckbox.html)(tr("Executable"));
if ( fileInfo.isExecutable() )
executable->setChecked(true);
[QGroupBox](qgroupbox.html) *ownerGroup = new [QGroupBox](qgroupbox.html)(tr("Ownership"));
[QLabel](qlabel.html) *ownerLabel = new [QLabel](qlabel.html)(tr("Owner"));
[QLabel](qlabel.html) *ownerValueLabel = new [QLabel](qlabel.html)(fileInfo.owner());
ownerValueLabel->setFrameStyle([QFrame](qframe.html)::Panel | [QFrame](qframe.html)::Sunken);
[QLabel](qlabel.html) *groupLabel = new [QLabel](qlabel.html)(tr("Group"));
[QLabel](qlabel.html) *groupValueLabel = new [QLabel](qlabel.html)(fileInfo.group());
groupValueLabel->setFrameStyle([QFrame](qframe.html)::Panel | [QFrame](qframe.html)::Sunken);
[QVBoxLayout](qvboxlayout.html) *permissionsLayout = new [QVBoxLayout](qvboxlayout.html);
permissionsLayout->addWidget(readable);
permissionsLayout->addWidget(writable);
permissionsLayout->addWidget(executable);
permissionsGroup->setLayout(permissionsLayout);
[QVBoxLayout](qvboxlayout.html) *ownerLayout = new [QVBoxLayout](qvboxlayout.html);
ownerLayout->addWidget(ownerLabel);
ownerLayout->addWidget(ownerValueLabel);
ownerLayout->addWidget(groupLabel);
ownerLayout->addWidget(groupValueLabel);
ownerGroup->setLayout(ownerLayout);
[QVBoxLayout](qvboxlayout.html) *mainLayout = new [QVBoxLayout](qvboxlayout.html);
mainLayout->addWidget(permissionsGroup);
mainLayout->addWidget(ownerGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);}
ApplicationsTab::ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QLabel *topLabel = new QLabel(tr("Open with:"));
[QListWidget](qlistwidget.html) *applicationsListBox = new [QListWidget](qlistwidget.html);
[QStringList](qstringlist.html) applications;
for (int i = 1; i <= 30; ++i)
applications.append(tr("Application %1").arg(i));
applicationsListBox->insertItems(0, applications);
[QCheckBox](qcheckbox.html) *alwaysCheckBox;
if (fileInfo.suffix().isEmpty())
alwaysCheckBox = new [QCheckBox](qcheckbox.html)(tr("Always use this application to "
"open this type of file"));
else
alwaysCheckBox = new [QCheckBox](qcheckbox.html)(tr("Always use this application to "
"open files with the extension '%1'").arg(fileInfo.suffix()));
[QVBoxLayout](qvboxlayout.html) *layout = new [QVBoxLayout](qvboxlayout.html);
layout->addWidget(topLabel);
layout->addWidget(applicationsListBox);
layout->addWidget(alwaysCheckBox);
setLayout(layout);}
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.