File indexing completed on 2024-04-21 08:30:10

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
0003    Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
0004    Copyright (C) 2005-2015 Jarosław Staniek <staniek@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KPROPERTY_PIXMAPEDIT_H
0023 #define KPROPERTY_PIXMAPEDIT_H
0024 
0025 #include "KPropertyWidgetsFactory.h"
0026 
0027 #include <QPixmap>
0028 #include <QVariant>
0029 
0030 class QLabel;
0031 class QPushButton;
0032 
0033 class KPROPERTYWIDGETS_EXPORT KPropertyPixmapEditor : public QWidget
0034 {
0035     Q_OBJECT
0036     Q_PROPERTY(QVariant value READ value WRITE setValue USER true)
0037 
0038 public:
0039     explicit KPropertyPixmapEditor(KProperty *prop, QWidget *parent = nullptr);
0040     ~KPropertyPixmapEditor() override;
0041 
0042     QVariant value() const;
0043 
0044 public Q_SLOTS:
0045     void setValue(const QVariant &value);
0046 
0047 Q_SIGNALS:
0048     void commitData( QWidget * editor );
0049 
0050 protected:
0051     bool eventFilter(QObject *o, QEvent *ev) override;
0052 
0053 protected Q_SLOTS:
0054     /*! Helper used by selectPixmap(). Can be also used by subclassess.
0055      Selected path will be stored in "lastVisitedImagePath" config entry within "Recent Dirs"
0056      config group of application's settings. This entry can be later reused when file dialogs
0057      are opened for selecting image files. */
0058     QString selectPixmapFileName();
0059 
0060     /*! Selects a new pixmap using "open" file dialog. Can be reimplemented. */
0061     virtual void selectPixmap();
0062 
0063 private:
0064     Q_DISABLE_COPY(KPropertyPixmapEditor)
0065     class Private;
0066     Private * const d;
0067 };
0068 
0069 class KPROPERTYWIDGETS_EXPORT KPropertyPixmapDelegate : public KPropertyEditorCreatorInterface,
0070                                                         public KPropertyValuePainterInterface,
0071                                                         public KPropertyValueDisplayInterface
0072 {
0073 public:
0074     KPropertyPixmapDelegate();
0075 
0076     QWidget *createEditor(int type, QWidget *parent, const QStyleOptionViewItem &option,
0077                           const QModelIndex &index) const override;
0078 
0079     void paint(QPainter *painter, const QStyleOptionViewItem &option,
0080                const QModelIndex &index) const override;
0081 
0082     QString valueToString(const QVariant &value, const QLocale &locale) const override;
0083 };
0084 
0085 #endif