22 #include "ppixmapedit.h" 25 #include <tqpainter.h> 30 #include <tdelocale.h> 32 #include "compat_tools.h" 36 #include <tdefiledialog.h> 38 #include <tqfiledialog.h> 40 #include <tqpushbutton.h> 44 PPixmapEdit::PPixmapEdit(MultiProperty* property, TQWidget* parent,
const char* name)
45 :PropertyWidget(property, parent, name)
47 TQHBoxLayout *l =
new TQHBoxLayout(
this, 0, 0);
48 m_edit =
new TQLabel(
this);
49 m_edit->setAlignment(TQt::AlignTop);
50 m_edit->resize(width(), height()-1);
51 m_edit->setBackgroundMode(TQt::PaletteBase);
52 m_edit->installEventFilter(
this);
54 m_button =
new TQPushButton(i18n(
"..."),
this);
55 m_button->resize(height(), height()-8);
56 m_button->move(width() - m_button->width() -1, 0);
57 m_button->setSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::Fixed);
59 l->addWidget(m_button);
60 m_popup =
new TQLabel(0, 0, TQt::WStyle_NoBorder|TQt::WX11BypassWM|WStyle_StaysOnTop);
64 connect(m_button, TQT_SIGNAL(clicked()),
this, TQT_SLOT(updateProperty()));
69 return TQVariant(*(m_edit->pixmap()));
74 p->setPen(TQt::NoPen);
75 p->setBrush(cg.background());
77 p->drawPixmap(r.topLeft().x(), r.topLeft().y(), value.toPixmap());
82 m_edit->setPixmap(value.toPixmap());
87 void PPixmapEdit::updateProperty()
90 KURL url = KFileDialog::getImageOpenURL(TQString(),
this);
93 m_edit->setPixmap(TQPixmap(url.path()));
97 TQString url = TQFileDialog::getOpenFileName();
100 m_edit->setPixmap(TQPixmap(url));
106 void PPixmapEdit::resizeEvent(TQResizeEvent *ev)
108 m_edit->resize(ev->size().width(), ev->size().height()-1);
109 m_button->move(ev->size().width() - m_button->width(), 0);
110 m_edit->setMaximumHeight(m_button->height());
113 bool PPixmapEdit::eventFilter(TQObject *o, TQEvent *ev)
115 if(TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_edit))
117 if(ev->type() == TQEvent::MouseButtonPress)
119 if(m_edit->pixmap()->size().height() < height()-2
120 && m_edit->pixmap()->size().width() < width()-20)
122 m_popup->setPixmap(*(m_edit->pixmap()));
123 m_popup->resize(m_edit->pixmap()->size());
124 m_popup->move(TQCursor::pos());
127 if(ev->type() == TQEvent::MouseButtonRelease)
129 if(m_popup->isVisible())
132 if(ev->type() == TQEvent::KeyPress)
134 TQKeyEvent* e = TQT_TQKEYEVENT(ev);
135 if((e->key() == Key_Enter) || (e->key()== Key_Space) || (e->key() == Key_Return))
137 m_button->animateClick();
142 return PropertyWidget::eventFilter(o, ev);
148 #include "ppixmapedit.moc" Namespace which contain property editing classes.
virtual TQVariant value() const
virtual TQVariant value() const
virtual void drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
Function to draw a property viewer when the editor isn't shown.
virtual void setValue(const TQVariant &value, bool emitChange)
Sets the value shown in the editor widget.