From c360489500f14c64774331ee8a178e0f6e9948c4 Mon Sep 17 00:00:00 2001 From: Alexander Wiedenbruch Date: Sun, 4 Mar 2007 20:35:37 +0000 Subject: [PATCH] New LineEdit based on QGraphicsTextItem svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=639321 --- CMakeLists.txt | 4 +++ widgets/lineedit.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ widgets/lineedit.h | 47 ++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 widgets/lineedit.cpp create mode 100644 widgets/lineedit.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b5879f0a..b90dc1554 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(plasma_LIB_SRCS datavisualization.cpp widgets/widget.cpp + widgets/lineedit.cpp + widgets/button.cpp ) kde4_automoc(${plasma_LIB_SRCS}) @@ -35,5 +37,7 @@ install( FILES dataengine.h widgets/widget.h + widgets/lineedit.h + widgets/button.h DESTINATION ${INCLUDE_INSTALL_DIR}/plasma ) diff --git a/widgets/lineedit.cpp b/widgets/lineedit.cpp new file mode 100644 index 000000000..bc0611807 --- /dev/null +++ b/widgets/lineedit.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2007 by Alexander Wiedenbruch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "lineedit.h" + +namespace Plasma +{ + +LineEdit::LineEdit(QGraphicsItem *parent, QGraphicsScene *scene) + : QGraphicsTextItem(parent, scene), + DataVisualization() +{ + setTextInteractionFlags(Qt::TextEditorInteraction); +} + +LineEdit::~LineEdit() +{ +} + +void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QStyleOptionFrameV2 panel; + panel.initFrom(widget); + panel.state = option->state; + panel.rect = boundingRect().toRect(); + + widget->style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, painter, widget); + widget->style()->drawPrimitive(QStyle::PE_FrameLineEdit, &panel, painter, widget); + + // QGraphicsTextItem paints a black frame when it has focus + // and is selected. We want to use our own frame, so we + // clear these flags. + QStyleOptionGraphicsItem *style = const_cast(option); + style->state &= ~(QStyle::State_Selected | QStyle::State_HasFocus); + + QGraphicsTextItem::paint(painter, style, widget); +} + +void LineEdit::data(const DataSource::Data&) +{ +} + +} // namespace Plasma diff --git a/widgets/lineedit.h b/widgets/lineedit.h new file mode 100644 index 000000000..0aead50f5 --- /dev/null +++ b/widgets/lineedit.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007 by Alexander Wiedenbruch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef LINEEDIT_H +#define LINEEDIT_H + +#include + +#include + +#include "datavisualization.h" + +namespace Plasma +{ + +class KDE_EXPORT LineEdit : public QGraphicsTextItem, + public DataVisualization +{ + public: + LineEdit(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); + ~LineEdit(); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + + public Q_SLOTS: + void data(const DataSource::Data&); + +}; + +} // namespace Plasma + +#endif