ppixmapedit.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ppixmapedit.h"
00023
00024 #include <qlayout.h>
00025 #include <qpainter.h>
00026 #include <qlabel.h>
00027 #include <qcursor.h>
00028
00029 #include <klocale.h>
00030 #include <kfiledialog.h>
00031 #include <kpushbutton.h>
00032
00033 namespace PropertyLib{
00034
00035 PPixmapEdit::PPixmapEdit(MultiProperty* property, QWidget* parent, const char* name)
00036 :PropertyWidget(property, parent, name)
00037 {
00038 QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00039 m_edit = new QLabel(this);
00040 m_edit->setAlignment(Qt::AlignTop);
00041 m_edit->resize(width(), height()-1);
00042 m_edit->setBackgroundMode(Qt::PaletteBase);
00043 m_edit->installEventFilter(this);
00044
00045 m_button = new KPushButton(i18n("..."), this);
00046 m_button->resize(height(), height()-8);
00047 m_button->move(width() - m_button->width() -1, 0);
00048 m_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
00049 l->addWidget(m_edit);
00050 l->addWidget(m_button);
00051 m_popup = new QLabel(0, 0, Qt::WStyle_NoBorder|Qt::WX11BypassWM|WStyle_StaysOnTop);
00052 m_popup->hide();
00053
00054
00055 connect(m_button, SIGNAL(clicked()), this, SLOT(updateProperty()));
00056 }
00057
00058 QVariant PPixmapEdit::value() const
00059 {
00060 return QVariant(*(m_edit->pixmap()));
00061 }
00062
00063 void PPixmapEdit::drawViewer(QPainter* p, const QColorGroup& cg, const QRect& r, const QVariant& value)
00064 {
00065 p->setPen(Qt::NoPen);
00066 p->setBrush(cg.background());
00067 p->drawRect(r);
00068 p->drawPixmap(r.topLeft().x(), r.topLeft().y(), value.toPixmap());
00069 }
00070
00071 void PPixmapEdit::setValue(const QVariant& value, bool emitChange)
00072 {
00073 m_edit->setPixmap(value.toPixmap());
00074 if (emitChange)
00075 emit propertyChanged(m_property, value);
00076 }
00077
00078 void PPixmapEdit::updateProperty()
00079 {
00080 KURL url = KFileDialog::getImageOpenURL(QString::null, this);
00081 if (!url.isEmpty())
00082 {
00083 m_edit->setPixmap(QPixmap(url.path()));
00084 emit propertyChanged(m_property, value());
00085 }
00086 }
00087
00088 void PPixmapEdit::resizeEvent(QResizeEvent *ev)
00089 {
00090 m_edit->resize(ev->size().width(), ev->size().height()-1);
00091 m_button->move(ev->size().width() - m_button->width(), 0);
00092 m_edit->setMaximumHeight(m_button->height());
00093 }
00094
00095 bool PPixmapEdit::eventFilter(QObject *o, QEvent *ev)
00096 {
00097 if(o == m_edit)
00098 {
00099 if(ev->type() == QEvent::MouseButtonPress)
00100 {
00101 if(m_edit->pixmap()->size().height() < height()-2
00102 && m_edit->pixmap()->size().width() < width()-20)
00103 return false;
00104 m_popup->setPixmap(*(m_edit->pixmap()));
00105 m_popup->resize(m_edit->pixmap()->size());
00106 m_popup->move(QCursor::pos());
00107 m_popup->show();
00108 }
00109 if(ev->type() == QEvent::MouseButtonRelease)
00110 {
00111 if(m_popup->isVisible())
00112 m_popup->hide();
00113 }
00114 if(ev->type() == QEvent::KeyPress)
00115 {
00116 QKeyEvent* e = static_cast<QKeyEvent*>(ev);
00117 if((e->key() == Key_Enter) || (e->key()== Key_Space) || (e->key() == Key_Return))
00118 {
00119 m_button->animateClick();
00120 return true;
00121 }
00122 }
00123 }
00124 return PropertyWidget::eventFilter(o, ev);
00125 }
00126
00127 }
00128
00129 #include "ppixmapedit.moc"
This file is part of the documentation for KDevelop Version 3.1.2.