syncthingtray/widgets/misc/textviewdialog.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

#include "./textviewdialog.h"
2017-07-08 01:31:41 +02:00
// use meta-data of syncthingtray application here
#include "resources/../../tray/resources/config.h"
#include <qtutilities/misc/dialogutils.h>
2017-05-01 03:34:43 +02:00
#include <QFontDatabase>
#include <QIcon>
2017-05-01 03:34:43 +02:00
#include <QKeyEvent>
#include <QTextBrowser>
#include <QVBoxLayout>
using namespace Dialogs;
namespace QtGui {
2017-05-01 03:34:43 +02:00
TextViewDialog::TextViewDialog(const QString &title, QWidget *parent)
: QWidget(parent, Qt::Window)
{
// set window title and icon
2017-05-01 03:34:43 +02:00
if (title.isEmpty()) {
setWindowTitle(QStringLiteral(APP_NAME));
} else {
setWindowTitle(title + QStringLiteral(" - " APP_NAME));
}
setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
// by default, delete on close
setAttribute(Qt::WA_DeleteOnClose);
// setup browser
m_browser = new QTextBrowser(this);
m_browser->setReadOnly(true);
m_browser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
// setup layout
auto *layout = new QVBoxLayout(this);
layout->setAlignment(Qt::AlignCenter);
layout->addWidget(m_browser);
setLayout(layout);
// default position and size
resize(600, 500);
centerWidget(this);
}
2016-12-11 20:52:46 +01:00
void TextViewDialog::keyPressEvent(QKeyEvent *event)
{
2017-05-01 03:34:43 +02:00
switch (event->key()) {
2016-12-11 20:52:46 +01:00
case Qt::Key_Escape:
close();
break;
case Qt::Key_F5:
emit reload();
break;
2017-05-01 03:34:43 +02:00
default:;
2016-12-11 20:52:46 +01:00
}
}
}