mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
gwenview: use specialized widget for messages
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
5a47c9280a
commit
287e95ac58
4 changed files with 152 additions and 158 deletions
|
@ -293,7 +293,7 @@ DocumentJob* Document::save(const KUrl& url, const QByteArray& format)
|
||||||
|
|
||||||
void Document::slotSaveResult(KJob* job)
|
void Document::slotSaveResult(KJob* job)
|
||||||
{
|
{
|
||||||
if (job->error()) {
|
if (job->error() != KJob::NoError) {
|
||||||
setErrorString(job->errorString());
|
setErrorString(job->errorString());
|
||||||
} else {
|
} else {
|
||||||
d->mUndoStack.setClean();
|
d->mUndoStack.setClean();
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>MessageView</class>
|
|
||||||
<widget class="QWidget" name="MessageView">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>400</width>
|
|
||||||
<height>300</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="1">
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>125</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>120</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" colspan="2">
|
|
||||||
<widget class="KMessageWidget" name="mMessageWidget">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="3">
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>120</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="2">
|
|
||||||
<spacer name="verticalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>125</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>KMessageWidget</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header location="global">kmessagewidget.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -21,43 +21,165 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
|
||||||
// Self
|
// Self
|
||||||
#include "moc_messageviewadapter.cpp"
|
#include "moc_messageviewadapter.cpp"
|
||||||
|
|
||||||
// Qt
|
// Katie
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsWidget>
|
||||||
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPen>
|
||||||
|
|
||||||
// KDE
|
// KDE
|
||||||
#include <KDebug>
|
|
||||||
#include <KLocale>
|
#include <KLocale>
|
||||||
|
#include <KColorScheme>
|
||||||
|
#include <KDebug>
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
#include <lib/document/document.h>
|
#include <lib/document/document.h>
|
||||||
#include <ui_messageview.h>
|
|
||||||
|
|
||||||
namespace Gwenview
|
namespace Gwenview
|
||||||
{
|
{
|
||||||
|
|
||||||
struct MessageViewAdapterPrivate : Ui_MessageView
|
static const qreal s_roundness = 4;
|
||||||
|
static const qreal s_bordersize = 0.6;
|
||||||
|
static const qreal s_margin = 4;
|
||||||
|
|
||||||
|
class MessageViewWidget : public QGraphicsWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum MessageType {
|
||||||
|
InformationType,
|
||||||
|
ErrorType
|
||||||
|
};
|
||||||
|
|
||||||
|
MessageViewWidget(MessageViewAdapter *adapter);
|
||||||
|
|
||||||
|
void setMessage(const MessageType type, const QString &main, const QString &detail);
|
||||||
|
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) final;
|
||||||
|
void keyPressEvent(QKeyEvent *event) final;
|
||||||
|
void changeEvent(QEvent *event) final;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateColors();
|
||||||
|
|
||||||
|
MessageViewAdapter* mAdapter;
|
||||||
|
MessageType mMessageType;
|
||||||
|
QString mText;
|
||||||
|
QTextOption mTextOptions;
|
||||||
|
QColor mInfoBg;
|
||||||
|
QColor mInfoBorder;
|
||||||
|
QColor mErrorBg;
|
||||||
|
QColor mErrorBorder;
|
||||||
|
};
|
||||||
|
|
||||||
|
MessageViewWidget::MessageViewWidget(MessageViewAdapter *adapter)
|
||||||
|
: QGraphicsWidget(),
|
||||||
|
mAdapter(adapter)
|
||||||
|
{
|
||||||
|
mTextOptions.setAlignment(Qt::AlignCenter);
|
||||||
|
mTextOptions.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||||
|
updateColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageViewWidget::setMessage(const MessageType type, const QString &main, const QString &detail)
|
||||||
|
{
|
||||||
|
mMessageType = type;
|
||||||
|
mText = main;
|
||||||
|
if (!detail.isEmpty()) {
|
||||||
|
mText.append(QLatin1String(":\n"));
|
||||||
|
mText.append(detail);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageViewWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
|
{
|
||||||
|
Q_UNUSED(widget);
|
||||||
|
const QRectF boundingrect = boundingRect();
|
||||||
|
QRectF mainrect = painter->boundingRect(boundingrect, mText, mTextOptions);
|
||||||
|
mainrect = mainrect.adjusted(-s_margin, -s_margin, s_margin, s_margin);
|
||||||
|
QBrush bgbrush;
|
||||||
|
QPen borderpen;
|
||||||
|
switch (mMessageType) {
|
||||||
|
case MessageViewWidget::InformationType: {
|
||||||
|
bgbrush = QBrush(mInfoBg);
|
||||||
|
borderpen = QPen(mInfoBorder);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MessageViewWidget::ErrorType: {
|
||||||
|
bgbrush = QBrush(mErrorBg);
|
||||||
|
borderpen = QPen(mErrorBorder);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
borderpen.setWidth(s_bordersize * 2);
|
||||||
|
painter->setPen(borderpen);
|
||||||
|
painter->drawRoundedRect(mainrect, s_roundness, s_roundness, Qt::AbsoluteSize);
|
||||||
|
painter->setBrush(bgbrush);
|
||||||
|
const QRectF subrect = mainrect.adjusted(s_bordersize, s_bordersize, -s_bordersize, -s_bordersize);
|
||||||
|
painter->drawRoundedRect(subrect, s_roundness, s_roundness, Qt::AbsoluteSize);
|
||||||
|
painter->setPen(option->palette.color(QPalette::Text));
|
||||||
|
painter->drawText(mainrect, mText, mTextOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageViewWidget::updateColors()
|
||||||
|
{
|
||||||
|
const KColorScheme scheme(QPalette::Active, KColorScheme::Window);
|
||||||
|
mInfoBg = scheme.background(KColorScheme::PositiveBackground).color();
|
||||||
|
mInfoBorder = KColorScheme::shade(mInfoBg, KColorScheme::DarkShade);
|
||||||
|
mErrorBg = scheme.background(KColorScheme::NegativeBackground).color();
|
||||||
|
mErrorBorder = KColorScheme::shade(mErrorBg, KColorScheme::DarkShade);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageViewWidget::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
|
if (event->modifiers() != Qt::NoModifier) {
|
||||||
|
QGraphicsWidget::keyPressEvent(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event->key()) {
|
||||||
|
case Qt::Key_Left:
|
||||||
|
case Qt::Key_Up: {
|
||||||
|
event->accept();
|
||||||
|
mAdapter->previousImageRequested();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::Key_Right:
|
||||||
|
case Qt::Key_Down: {
|
||||||
|
event->accept();
|
||||||
|
mAdapter->nextImageRequested();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QGraphicsWidget::keyPressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageViewWidget::changeEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
QGraphicsWidget::changeEvent(event);
|
||||||
|
if (event->type() == QEvent::PaletteChange) {
|
||||||
|
updateColors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MessageViewAdapterPrivate
|
||||||
{
|
{
|
||||||
Document::Ptr mDocument;
|
Document::Ptr mDocument;
|
||||||
|
MessageViewWidget* mMessageViewWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageViewAdapter::MessageViewAdapter()
|
MessageViewAdapter::MessageViewAdapter()
|
||||||
: d(new MessageViewAdapterPrivate)
|
: d(new MessageViewAdapterPrivate())
|
||||||
{
|
{
|
||||||
QWidget* widget = new QWidget;
|
d->mMessageViewWidget = new MessageViewWidget(this);
|
||||||
widget->installEventFilter(this);
|
setWidget(d->mMessageViewWidget);
|
||||||
d->setupUi(widget);
|
|
||||||
d->mMessageWidget->setCloseButtonVisible(false);
|
|
||||||
d->mMessageWidget->setWordWrap(true);
|
|
||||||
|
|
||||||
setInfoMessage(i18n("No document selected"));
|
setInfoMessage(i18n("No document selected"));
|
||||||
|
|
||||||
widget->setAutoFillBackground(true);
|
|
||||||
widget->setBackgroundRole(QPalette::Base);
|
|
||||||
widget->setForegroundRole(QPalette::Text);
|
|
||||||
|
|
||||||
QGraphicsProxyWidget* proxy = new QGraphicsProxyWidget;
|
|
||||||
proxy->setWidget(widget);
|
|
||||||
setWidget(proxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageViewAdapter::~MessageViewAdapter()
|
MessageViewAdapter::~MessageViewAdapter()
|
||||||
|
@ -68,29 +190,21 @@ MessageViewAdapter::~MessageViewAdapter()
|
||||||
void MessageViewAdapter::setErrorMessage(const QString& main, const QString& detail)
|
void MessageViewAdapter::setErrorMessage(const QString& main, const QString& detail)
|
||||||
{
|
{
|
||||||
if (main.isEmpty()) {
|
if (main.isEmpty()) {
|
||||||
d->mMessageWidget->hide();
|
d->mMessageViewWidget->hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
d->mMessageWidget->show();
|
d->mMessageViewWidget->show();
|
||||||
d->mMessageWidget->setMessageType(KMessageWidget::Error);
|
d->mMessageViewWidget->setMessage(MessageViewWidget::ErrorType, main, detail);
|
||||||
QString message;
|
|
||||||
if (detail.isEmpty()) {
|
|
||||||
message = main;
|
|
||||||
} else {
|
|
||||||
message = QString("<b>%1</b><br>%2").arg(main).arg(detail);
|
|
||||||
}
|
|
||||||
d->mMessageWidget->setText(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageViewAdapter::setInfoMessage(const QString& message)
|
void MessageViewAdapter::setInfoMessage(const QString& message)
|
||||||
{
|
{
|
||||||
if (message.isEmpty()) {
|
if (message.isEmpty()) {
|
||||||
d->mMessageWidget->hide();
|
d->mMessageViewWidget->hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
d->mMessageWidget->show();
|
d->mMessageViewWidget->show();
|
||||||
d->mMessageWidget->setMessageType(KMessageWidget::Information);
|
d->mMessageViewWidget->setMessage(MessageViewWidget::InformationType, message, QString());
|
||||||
d->mMessageWidget->setText(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Ptr MessageViewAdapter::document() const
|
Document::Ptr MessageViewAdapter::document() const
|
||||||
|
@ -103,28 +217,7 @@ void MessageViewAdapter::setDocument(Document::Ptr doc)
|
||||||
d->mDocument = doc;
|
d->mDocument = doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessageViewAdapter::eventFilter(QObject*, QEvent* ev)
|
|
||||||
{
|
|
||||||
if (ev->type() == QEvent::KeyPress) {
|
|
||||||
QKeyEvent* event = static_cast<QKeyEvent*>(ev);
|
|
||||||
if (event->modifiers() != Qt::NoModifier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event->key()) {
|
|
||||||
case Qt::Key_Left:
|
|
||||||
case Qt::Key_Up:
|
|
||||||
previousImageRequested();
|
|
||||||
break;
|
|
||||||
case Qt::Key_Right:
|
|
||||||
case Qt::Key_Down:
|
|
||||||
nextImageRequested();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#include "messageviewadapter.moc"
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
|
||||||
#ifndef MESSAGEVIEWADAPTER_H
|
#ifndef MESSAGEVIEWADAPTER_H
|
||||||
#define MESSAGEVIEWADAPTER_H
|
#define MESSAGEVIEWADAPTER_H
|
||||||
|
|
||||||
// Qt
|
|
||||||
|
|
||||||
// KDE
|
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
#include <lib/documentview/abstractdocumentviewadapter.h>
|
#include <lib/documentview/abstractdocumentviewadapter.h>
|
||||||
|
|
||||||
|
@ -52,10 +48,8 @@ public:
|
||||||
|
|
||||||
void setErrorMessage(const QString& main, const QString& detail = QString());
|
void setErrorMessage(const QString& main, const QString& detail = QString());
|
||||||
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject*, QEvent*);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class MessageViewWidget;
|
||||||
MessageViewAdapterPrivate* const d;
|
MessageViewAdapterPrivate* const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue