Commit ed396178 authored by Elvis Angelaccio's avatar Elvis Angelaccio

Introduce arkviewer.ui

This patch simplifies ArkViewer by moving its UI code to arkviewer.ui

Differential Revision: D1669
parent 04a6386f
......@@ -16,8 +16,10 @@ ecm_qt_declare_logging_category(arkpart_PART_SRCS
qt5_add_dbus_adaptor(arkpart_PART_SRCS dnddbusinterface.xml part.h Ark::Part)
ki18n_wrap_ui(arkpart_PART_SRCS infopanel.ui)
ki18n_wrap_ui(arkpart_PART_SRCS jobtracker.ui)
ki18n_wrap_ui(arkpart_PART_SRCS
arkviewer.ui
infopanel.ui
jobtracker.ui)
add_library(arkpart MODULE ${arkpart_PART_SRCS})
......
......@@ -32,12 +32,7 @@
#include <QProgressDialog>
#include <QDebug>
#include <QHBoxLayout>
#include <QFile>
#include <QFrame>
#include <QLabel>
#include <QKeyEvent>
#include <QPushButton>
#include <QMimeDatabase>
ArkViewer::ArkViewer()
......@@ -47,17 +42,9 @@ ArkViewer::ArkViewer()
setAttribute(Qt::WA_DeleteOnClose);
// Set a QVBoxLayout as main layout of dialog
m_mainLayout = new QVBoxLayout(this);
setLayout(m_mainLayout);
// Add a close button
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
m_mainLayout->addWidget(buttonBox);
buttonBox->button(QDialogButtonBox::Close)->setDefault(true);
buttonBox->button(QDialogButtonBox::Close)->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
setupUi(this);
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(this, &ArkViewer::finished, this, &ArkViewer::dialogClosed);
}
......@@ -183,14 +170,6 @@ void ArkViewer::view(const QString& fileName)
QFile::remove(fileName);
}
// This sets the default size of the dialog. It will only take effect in the case
// where there is no saved size in the config file - it sets the default values
// for KDialog::restoreDialogSize().
QSize ArkViewer::sizeHint() const
{
return QSize(560, 400);
}
bool ArkViewer::viewInInternalViewer(const QString& fileName, const QMimeType &mimeType)
{
setWindowFilePath(fileName);
......@@ -199,26 +178,10 @@ bool ArkViewer::viewInInternalViewer(const QString& fileName, const QMimeType &m
KConfigGroup group(KSharedConfig::openConfig(), "Viewer");
KWindowConfig::restoreWindowSize(windowHandle(), group);
// Create a QFrame for the header
QFrame *header = new QFrame();
QHBoxLayout *headerHLayout = new QHBoxLayout(header);
// Add an icon representing the mimetype to header
QLabel *iconLabel = new QLabel(header);
headerHLayout->addWidget(iconLabel);
iconLabel->setPixmap(QIcon::fromTheme(mimeType.iconName()).pixmap(IconSize(KIconLoader::Desktop), IconSize(KIconLoader::Desktop)));
iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
// Add file name and mimetype to header
QVBoxLayout *headerVLayout = new QVBoxLayout();
headerVLayout->setSpacing(0);
headerVLayout->addWidget(new QLabel(QStringLiteral("<qt><b>%1</b></qt>").arg(fileName)));
headerVLayout->addWidget(new QLabel(mimeType.comment()));
headerHLayout->addLayout(headerVLayout);
header->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
m_mainLayout->insertWidget(0, header);
// Set icon and comment for the mimetype.
m_iconLabel->setPixmap(QIcon::fromTheme(mimeType.iconName()).pixmap(IconSize(KIconLoader::Desktop), IconSize(KIconLoader::Desktop)));
m_commentLabel->setText(mimeType.comment());
// Create the ReadOnlyPart instance.
m_part = KMimeTypeTrader::self()->createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType.name(), this, this);
......@@ -237,8 +200,8 @@ bool ArkViewer::viewInInternalViewer(const QString& fileName, const QMimeType &m
return false;
}
// Insert the KPart into the main layout.
m_mainLayout->insertWidget(1, m_part.data()->widget());
// Insert the KPart into its placeholder.
layout()->replaceWidget(m_partPlaceholder, m_part.data()->widget());
m_part.data()->openUrl(QUrl::fromLocalFile(fileName));
......
......@@ -22,6 +22,8 @@
#ifndef ARKVIEWER_H
#define ARKVIEWER_H
#include "ui_arkviewer.h"
#include <KParts/BrowserExtension>
#include <KParts/ReadOnlyPart>
#include <KService>
......@@ -29,15 +31,13 @@
#include <QDialog>
#include <QWeakPointer>
#include <QMimeType>
#include <QVBoxLayout>
class ArkViewer : public QDialog
class ArkViewer : public QDialog, public Ui::ArkViewer
{
Q_OBJECT
public:
virtual ~ArkViewer();
QSize sizeHint() const Q_DECL_OVERRIDE;
static void view(const QString& fileName);
......@@ -51,7 +51,6 @@ private:
bool viewInInternalViewer(const QString& fileName, const QMimeType& mimeType);
QPointer<KParts::ReadOnlyPart> m_part;
QVBoxLayout *m_mainLayout;
};
#endif // ARKVIEWER_H
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ArkViewer</class>
<widget class="QDialog" name="ArkViewer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="m_mimeWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="m_iconLabel">
<property name="text">
<string notr="true">mime icon</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_commentLabel">
<property name="text">
<string notr="true">mime comment</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="m_partPlaceholder" native="true"/>
</item>
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>m_buttonBox</sender>
<signal>accepted()</signal>
<receiver>ArkViewer</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_buttonBox</sender>
<signal>rejected()</signal>
<receiver>ArkViewer</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment