1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*
* This file is part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2012 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2004 Christian Muehlhaeuser <chris@chris.de>
* Copyright (c) 2004-2006 Seb Ruiz <ruiz@kde.org>
* Copyright (c) 2004,2005 Max Howell <max.howell@methylblue.com>
* Copyright (c) 2005 Gabor Lehel <illissius@gmail.com>
* Copyright (c) 2008,2009 Mark Kretschmann <kretschmann@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_FLOATING_MESSAGE_H
#define KIS_FLOATING_MESSAGE_H
#include <QWidget>
#include <QString>
#include <QImage>
#include <QTimer>
#include <QTimeLine>
#include <kritaui_export.h>
/**
* @brief The KisFloatingMessage class shows the given message in a semi-transparent
* bubble that doesn' take focus and slowly fades away.
*
* Heavily based on Amarok's Osd.cpp
*/
class KRITAUI_EXPORT KisFloatingMessage : public QWidget
{
Q_OBJECT
public:
enum Priority {
High = 0,
Medium,
Low
};
explicit KisFloatingMessage(const QString &message, QWidget *parent, bool showOverParent, int timeout,
Priority priority, int alignment = Qt::AlignCenter | Qt::TextWordWrap);
/// Show message above parent widget instead of screen
void setShowOverParent(bool show);
void setIcon(const QIcon& icon);
void tryOverrideMessage(const QString message,
const QIcon& icon,
int timeout,
KisFloatingMessage::Priority priority,
int alignment = Qt::AlignCenter | Qt::TextWordWrap);
protected:
void paintEvent(QPaintEvent *e) override;
public Q_SLOTS:
void showMessage();
void removeMessage();
private Q_SLOTS:
void startFade();
void updateOpacity(int value);
void widgetDeleted();
private:
QRect determineMetrics(const int M);
QString m_message;
QImage m_icon;
QPixmap m_scaledIcon;
QTimer m_timer;
int m_m;
QTimeLine m_fadeTimeLine;
bool m_showOverParent;
int m_timeout;
Priority m_priority;
int m_alignment;
bool widgetQueuedForDeletion;
};
#endif // KIS_FLOATING_MESSAGE_H
|