plasma-framework/src/plasmaquick/dialog.h

230 lines
7.8 KiB
C
Raw Normal View History

/***************************************************************************
* Copyright 2011 Marco Martin <mart@kde.org> *
* Copyright 2013 Sebastian Kügler <sebas@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 DIALOG_PROXY_P
#define DIALOG_PROXY_P
#include <QQuickItem>
#include <QQuickWindow>
#include <QWeakPointer>
#include <QPoint>
#include <QQmlParserStatus>
#include <Plasma/Plasma>
2014-01-23 15:17:18 +01:00
#include <Plasma/Theme>
2013-10-30 14:08:32 +01:00
#include <netwm_def.h>
#include <plasmaquick_export.h>
//
// W A R N I N G
// -------------
//
// This file is not part of the public Plasma API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
class QQuickItem;
class QScreen;
2014-04-26 01:45:47 +02:00
namespace PlasmaQuick
{
2014-03-19 11:59:15 +01:00
class DialogPrivate;
/**
* @class Dialog
* @short QML wrapper for dialogs
*
2013-02-26 05:47:12 +01:00
* Exposed as `PlasmaCore.Dialog` in QML.
*/
class PLASMAQUICK_EXPORT Dialog : public QQuickWindow, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
2011-12-23 14:50:34 +01:00
/**
* The main QML item that will be displayed in the Dialog
*/
Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
2011-12-23 14:50:34 +01:00
/**
* The main QML item that will be displayed in the Dialog
*/
Q_PROPERTY(QQuickItem *visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged)
2011-12-23 14:50:34 +01:00
/**
* Margins of the dialog around the mainItem.
* @see DialogMargins
*/
Q_PROPERTY(QObject *margins READ margins CONSTANT)
2011-12-23 14:50:34 +01:00
/**
* Plasma Location of the dialog window. Useful if this dialog is a popup for a panel
2011-12-23 14:50:34 +01:00
*/
2013-10-18 16:50:56 +02:00
Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged)
2013-10-30 14:08:32 +01:00
/**
* Type of the window
*/
Q_PROPERTY(WindowType type READ type WRITE setType NOTIFY typeChanged)
/**
* Whether the dialog should be hidden when the dialog loses focus.
*
* The default value is @c false.
**/
Q_PROPERTY(bool hideOnWindowDeactivate READ hideOnWindowDeactivate WRITE setHideOnWindowDeactivate NOTIFY hideOnWindowDeactivateChanged)
/**
* Whether the dialog is output only. Default value is @c false. If it is @c true
* the dialog does not accept input and all pointer events are not accepted, thus the dialog
* is click through.
*
* This property is currently only supported on the X11 platform. On any other platform the
* property has no effect.
**/
Q_PROPERTY(bool outputOnly READ isOutputOnly WRITE setOutputOnly NOTIFY outputOnlyChanged)
2014-03-19 11:55:00 +01:00
/**
* This property holds the window flags of the window.
* The window flags control the window's appearance in the windowing system,
* whether it's a dialog, popup, or a regular window, and whether it should
* have a title bar, etc.
* Regardless to what the user sets, the flags will always have the
* FramelessWindowHint flag set
*/
2014-02-25 16:30:13 +01:00
Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFramelessFlags NOTIFY flagsChanged)
/**
* This property holds how (and if at all) the dialog should draw its own background
2014-08-21 14:55:16 +02:00
* or if it is complete responsibility of the content item to render a background.
* Note that in case of NoBackground it loses kwin side shadows and blur
*/
Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints NOTIFY backgroundHintsChanged)
2013-02-20 19:31:06 +01:00
Q_CLASSINFO("DefaultProperty", "mainItem")
public:
2013-10-30 14:08:32 +01:00
enum WindowType {
Normal = NET::Normal,
Dock = NET::Dock,
2014-03-18 21:34:58 +01:00
DialogWindow = NET::Dialog,
2013-10-30 14:08:32 +01:00
PopupMenu = NET::PopupMenu,
Tooltip = NET::Tooltip,
Notification = NET::Notification
2011-02-25 19:00:01 +01:00
};
2013-10-30 14:08:32 +01:00
Q_ENUMS(WindowType)
2011-02-25 19:00:01 +01:00
enum BackgroundHints {
NoBackground = 0, /**< Not drawing a background under the applet, the dialog has its own implementation */
StandardBackground = 1 /**< The standard background from the theme is drawn */
};
Q_ENUMS(BackgroundHints)
2014-03-18 21:34:58 +01:00
Dialog(QQuickItem *parent = 0);
~Dialog();
2014-03-19 11:32:01 +01:00
//PROPERTIES ACCESSORS
QQuickItem *mainItem() const;
void setMainItem(QQuickItem *mainItem);
QQuickItem *visualParent() const;
void setVisualParent(QQuickItem *visualParent);
2013-10-18 16:50:56 +02:00
Plasma::Types::Location location() const;
void setLocation(Plasma::Types::Location location);
QObject *margins() const;
2014-02-25 16:30:13 +01:00
void setFramelessFlags(Qt::WindowFlags flags);
2011-12-23 14:50:34 +01:00
2013-10-30 14:08:32 +01:00
void setType(WindowType type);
WindowType type() const;
2014-03-19 11:55:00 +01:00
bool hideOnWindowDeactivate() const;
void setHideOnWindowDeactivate(bool hide);
void setOutputOnly(bool outputOnly);
bool isOutputOnly() const;
BackgroundHints backgroundHints() const;
void setBackgroundHints(BackgroundHints hints);
2014-03-19 11:32:01 +01:00
/**
* @returns The suggested screen position for the popup
* @arg item the item the popup has to be positioned relatively to. if null, the popup will be positioned in the center of the window
* @arg alignment alignment of the popup compared to the item
*/
virtual QPoint popupPosition(QQuickItem *item, const QSize &size);
Q_SIGNALS:
void mainItemChanged();
void locationChanged();
void visualParentChanged();
2013-10-30 14:08:32 +01:00
void typeChanged();
void hideOnWindowDeactivateChanged();
void outputOnlyChanged();
2014-02-25 16:30:13 +01:00
void flagsChanged();
void backgroundHintsChanged();
/**
* Emitted when the @see hideOnWindowDeactivate property is @c true and this dialog lost focus to a
* window that is neither a parent dialog to nor a child dialog of this dialog.
*/
void windowDeactivated();
2011-02-25 20:37:56 +01:00
protected:
2014-03-19 11:32:01 +01:00
/*
* set the dialog position. subclasses may change it. ToolTipDialog adjusts the position in an animated way
*/
virtual void adjustGeometry(const QRect &geom);
2014-03-19 11:21:54 +01:00
//Reimplementations
virtual void classBegin();
virtual void componentComplete();
2014-03-19 11:21:54 +01:00
virtual void resizeEvent(QResizeEvent *re);
virtual void focusInEvent(QFocusEvent *ev);
virtual void focusOutEvent(QFocusEvent *ev);
virtual void showEvent(QShowEvent *event);
virtual void hideEvent(QHideEvent *event);
virtual bool event(QEvent *event);
private:
2014-03-19 11:32:01 +01:00
friend class DialogPrivate;
DialogPrivate *const d;
2014-03-19 10:23:25 +01:00
Q_PRIVATE_SLOT(d, void syncBorders())
2014-06-10 15:22:12 +02:00
Q_PRIVATE_SLOT(d, void updateTheme())
2014-03-19 10:23:25 +01:00
Q_PRIVATE_SLOT(d, void updateVisibility(bool visible))
2014-03-19 18:30:56 +01:00
Q_PRIVATE_SLOT(d, void updateInputShape())
2014-03-19 10:23:25 +01:00
Q_PRIVATE_SLOT(d, void updateMinimumWidth())
Q_PRIVATE_SLOT(d, void updateMinimumHeight())
Q_PRIVATE_SLOT(d, void updateMaximumWidth())
Q_PRIVATE_SLOT(d, void updateMaximumHeight())
};
2014-03-19 11:59:15 +01:00
}
#endif