File indexing completed on 2024-11-24 04:39:32
0001 /* 0002 This file is part of Contact Editor. 0003 0004 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <KContacts/Picture> 0012 0013 #include <QPoint> 0014 #include <QPushButton> 0015 0016 namespace KContacts 0017 { 0018 class Addressee; 0019 } 0020 namespace Akonadi 0021 { 0022 class ImageLoader; 0023 0024 class ImageWidget : public QPushButton 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 enum Type { Photo, Logo }; 0030 0031 explicit ImageWidget(Type type, QWidget *parent = nullptr); 0032 ~ImageWidget() override; 0033 0034 void loadContact(const KContacts::Addressee &contact); 0035 void storeContact(KContacts::Addressee &contact) const; 0036 0037 void setReadOnly(bool readOnly); 0038 0039 protected: 0040 // image drop handling 0041 void dragEnterEvent(QDragEnterEvent *event) override; 0042 void dropEvent(QDropEvent *event) override; 0043 0044 // image drag handling 0045 void mousePressEvent(QMouseEvent *event) override; 0046 void mouseMoveEvent(QMouseEvent *event) override; 0047 0048 // context menu handling 0049 void contextMenuEvent(QContextMenuEvent *event) override; 0050 0051 private: 0052 void updateView(); 0053 0054 void changeImage(); 0055 void changeUrl(); 0056 void saveImage(); 0057 void deleteImage(); 0058 ImageLoader *imageLoader(); 0059 0060 KContacts::Picture mPicture; 0061 QPoint mDragStartPos; 0062 ImageLoader *mImageLoader = nullptr; 0063 Type mType; 0064 bool mHasImage; 0065 bool mReadOnly; 0066 }; 0067 }