• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Property Editing Library
 

KDevelop Property Editing Library

  • lib
  • widgets
  • propeditor
ppixmapedit.cpp
1 /***************************************************************************
2  * Copyright (C) 2003 Cedric Pasteur *
3  * <cedric.pasteur@free.fr> *
4  * Copyright (C) 2004 by Alexander Dymo *
5  * cloudtemple@mskat.net *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU Library General Public License as *
9  * published by the Free Software Foundation; either version 2 of the *
10  * License, or (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Library General Public *
18  * License along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
21  ***************************************************************************/
22 #include "ppixmapedit.h"
23 
24 #include <tqlayout.h>
25 #include <tqpainter.h>
26 #include <tqlabel.h>
27 #include <tqcursor.h>
28 
29 #ifndef PURE_QT
30 #include <tdelocale.h>
31 #else
32 #include "compat_tools.h"
33 #endif
34 
35 #ifndef PURE_QT
36 #include <tdefiledialog.h>
37 #else
38 #include <tqfiledialog.h>
39 #endif
40 #include <tqpushbutton.h>
41 
42 namespace PropertyLib{
43 
44 PPixmapEdit::PPixmapEdit(MultiProperty* property, TQWidget* parent, const char* name)
45  :PropertyWidget(property, parent, name)
46 {
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);
53 
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);
58  l->addWidget(m_edit);
59  l->addWidget(m_button);
60  m_popup = new TQLabel(0, 0, TQt::WStyle_NoBorder|TQt::WX11BypassWM|WStyle_StaysOnTop);
61  m_popup->hide();
62 
63 
64  connect(m_button, TQT_SIGNAL(clicked()), this, TQT_SLOT(updateProperty()));
65 }
66 
67 TQVariant PPixmapEdit::value() const
68 {
69  return TQVariant(*(m_edit->pixmap()));
70 }
71 
72 void PPixmapEdit::drawViewer(TQPainter* p, const TQColorGroup& cg, const TQRect& r, const TQVariant& value)
73 {
74  p->setPen(TQt::NoPen);
75  p->setBrush(cg.background());
76  p->drawRect(r);
77  p->drawPixmap(r.topLeft().x(), r.topLeft().y(), value.toPixmap());
78 }
79 
80 void PPixmapEdit::setValue(const TQVariant& value, bool emitChange)
81 {
82  m_edit->setPixmap(value.toPixmap());
83  if (emitChange)
84  emit propertyChanged(m_property, value);
85 }
86 
87 void PPixmapEdit::updateProperty()
88 {
89 #ifndef PURE_QT
90  KURL url = KFileDialog::getImageOpenURL(TQString(), this);
91  if (!url.isEmpty())
92  {
93  m_edit->setPixmap(TQPixmap(url.path()));
94  emit propertyChanged(m_property, value());
95  }
96 #else
97  TQString url = TQFileDialog::getOpenFileName();
98  if (!url.isEmpty())
99  {
100  m_edit->setPixmap(TQPixmap(url));
101  emit propertyChanged(m_property, value());
102  }
103 #endif
104 }
105 
106 void PPixmapEdit::resizeEvent(TQResizeEvent *ev)
107 {
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());
111 }
112 
113 bool PPixmapEdit::eventFilter(TQObject *o, TQEvent *ev)
114 {
115  if(TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_edit))
116  {
117  if(ev->type() == TQEvent::MouseButtonPress)
118  {
119  if(m_edit->pixmap()->size().height() < height()-2
120  && m_edit->pixmap()->size().width() < width()-20)
121  return false;
122  m_popup->setPixmap(*(m_edit->pixmap()));
123  m_popup->resize(m_edit->pixmap()->size());
124  m_popup->move(TQCursor::pos());
125  m_popup->show();
126  }
127  if(ev->type() == TQEvent::MouseButtonRelease)
128  {
129  if(m_popup->isVisible())
130  m_popup->hide();
131  }
132  if(ev->type() == TQEvent::KeyPress)
133  {
134  TQKeyEvent* e = TQT_TQKEYEVENT(ev);
135  if((e->key() == Key_Enter) || (e->key()== Key_Space) || (e->key() == Key_Return))
136  {
137  m_button->animateClick();
138  return true;
139  }
140  }
141  }
142  return PropertyWidget::eventFilter(o, ev);
143 }
144 
145 }
146 
147 #ifndef PURE_QT
148 #include "ppixmapedit.moc"
149 #endif
PropertyLib
Namespace which contain property editing classes.
Definition: childproperty.cpp:29
PropertyLib::PLineStyleEdit::value
virtual TQVariant value() const
Definition: plinestyleedit.cpp:146
PropertyLib::PPixmapEdit::value
virtual TQVariant value() const
Definition: ppixmapedit.cpp:67
PropertyLib::PPixmapEdit::drawViewer
virtual void drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
Function to draw a property viewer when the editor isn&#39;t shown.
Definition: ppixmapedit.cpp:72
PropertyLib::PropertyWidget::propertyChanged
void propertyChanged(MultiProperty *property, const TQVariant &value)
Emit this signal when property value is changed.
PropertyLib::PPixmapEdit::setValue
virtual void setValue(const TQVariant &value, bool emitChange)
Sets the value shown in the editor widget.
Definition: ppixmapedit.cpp:80

KDevelop Property Editing Library

Skip menu "KDevelop Property Editing Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDevelop Property Editing Library

Skip menu "KDevelop Property Editing Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Property Editing Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.