no longer used

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=807767
This commit is contained in:
Aaron J. Seigo 2008-05-14 17:16:36 +00:00
parent 454cdf7022
commit 102cd5b748
12 changed files with 0 additions and 2318 deletions

View File

@ -1,241 +0,0 @@
/*
* Copyright 2007 by Siraj Razick <siraj@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 "checkbox.h"
#include <QStyleOption>
#include <QStyle>
#include <QWidget>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
namespace Plasma
{
class CheckBox::Private
{
public:
Private() { }
~Private() { }
QString labelText;
QString labelIcon;
QColor labelTextColor;
QIcon icon;
QSize iconSize;
bool hasIcon;
bool hasMouse;
int labelTextOpacity;
int height;
int width;
int maxWidth;
int radius;
QTimer * updateTimer;
Qt::CheckState state;
bool down;
bool hovering;
};
CheckBox::CheckBox(QGraphicsItem *parent)
: Plasma::Widget(parent),
d(new Private)
{
init();
}
CheckBox::CheckBox(const QString &text, QGraphicsItem *parent)
: Plasma::Widget(parent),
d(new Private)
{
init();
setText(text);
}
void CheckBox::init()
{
setAcceptedMouseButtons(Qt::LeftButton);
setAcceptsHoverEvents(true);
setAcceptDrops(true);
setEnabled(true);
setPos(QPointF(0.0,0.0));
d->height = 40;
d->width = 100 ;
d->maxWidth = 600;
d->state= Qt::Unchecked;
d->hasIcon = false;
d->iconSize = QSize(32,32);
d->hasMouse = false;
d->down = false;
d->hovering = false;
d->down = false;
}
CheckBox::~CheckBox()
{
delete d;
}
void CheckBox::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
QStyleOptionButton options;
options.rect = boundingRect().toRect();
options.text = text();
options.state |= (d->state == Qt::Checked) ? QStyle::State_On : QStyle::State_Off;
//if (d->down) {
// options.state |= QStyle::State_Sunken;
// }
if (d->hasMouse) {
options.state |= QStyle::State_MouseOver;
options.state |= QStyle::State_HasFocus;
options.state |= QStyle::State_Sunken;
options.state |= QStyle::State_Raised;
options.state |= QStyle::State_On;
}
widget-> style()->drawControl(QStyle::CE_CheckBox, &options, painter, widget);
}
void CheckBox::dataUpdated(const QString&, const DataEngine::Data& data)
{
foreach (const QVariant& variant, data) {
if (variant.canConvert(QVariant::Bool)) {
setChecked(variant.toBool());
return;
}
}
}
void CheckBox::setText(const QString& text)
{
d->labelText = text;
/*
QFont * _font = new QFont ( text );
QFontMetrics fm ( *_font );
if ( fm.width(text) >= d->width ) {
setWidth(fm.width(text)+4);
}
delete _font;
*/
}
QString CheckBox::text() const
{
return d->labelText;
}
Qt::CheckState CheckBox::checkState() const
{
return d->state;
}
void CheckBox::setChecked(bool checked)
{
d->state = checked ? Qt::Checked : Qt::Unchecked;
}
bool CheckBox::isChecked() const
{
return (d->state == Qt::Checked);
}
void CheckBox::setCheckState(Qt::CheckState state)
{
d->state = state;
}
void CheckBox::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
event->accept();
d->hasMouse= false;
}
void CheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
event->accept();
d->down = true;
update();
}
void CheckBox::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
event->accept();
if (d->hasMouse) {
if (d->state == Qt::Checked) {
d->state = Qt::Unchecked;
} else {
d->state = Qt::Checked;
}
}
update();
if (sceneBoundingRect().contains(event->scenePos())) {
emit clicked();
}
}
void CheckBox::hoverMoveEvent(QGraphicsSceneHoverEvent * event)
{
event->accept();
d->hasMouse= true;
update();
}
void CheckBox::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
{
event->accept();
d->hasMouse= false;
update();
Widget::hoverEnterEvent(event);
}
void CheckBox::hoverEnterEvent ( QGraphicsSceneHoverEvent * event)
{
event->accept();
d->hasMouse = true;
update();
Widget::hoverLeaveEvent(event);
}
/*
void CheckBox::dragLeaveEvent ( QGraphicsSceneDragDropEvent * event )
{
event->accept();
}
*/
} // namespace Plasma
#include "checkbox.moc"

View File

@ -1,132 +0,0 @@
/*
* Copyright 2007 by Siraj Razick <siraj@kde.org>
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 CHECKBOX_H
#define CHECKBOX_H
#include <QtCore/QObject>
#include <QtGui/QGraphicsItem>
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
#include <plasma/widgets/widget.h>
namespace Plasma
{
/**
* This class provides a QCheckBox available as a Plasma::Widget, so it can be used
* within Plasma::Applet's.
*
* @author Siraj Razick <siraj@kde.org>
*/
class PLASMA_EXPORT CheckBox : public Plasma::Widget
{
Q_OBJECT
public:
/**
* Creates a new Plasma::CheckBox.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit CheckBox(QGraphicsItem *parent = 0);
/**
* Creates a new Plasma::Icon with default text.
* @param text the text to display next to the checkbox.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit CheckBox(const QString &text, QGraphicsItem *parent = 0);
/**
* Destroys a Plasma::Icon.
*/
virtual ~CheckBox();
/**
* @return whether this checkbox is currently checked.
*/
bool isChecked() const;
/**
* Sets the checked state of this Plasma::CheckBox.
* @param checked whether the Plasma::CheckBox is checked or not.
*/
void setChecked(bool checked);
/**
* @return the checkstate of this Plasma::CheckBox.
*/
Qt::CheckState checkState() const;
/**
* Sets the checkstate of this Plasma::CheckBox
* @see <qt.h> for definition of Qt::CheckState
* @param state the checkstate of this Plasma::CheckBox
*/
void setCheckState(Qt::CheckState state);
/**
* @return the text associated with this Plasma::CheckBox
*/
QString text() const;
/**
* Sets the text associated with this Plasma::CheckBox
* @param text the text to associate with this Plasma::CheckBox.
*/
void setText(const QString &text);
/*
bool isTristate() const;
void setTristate(bool triState = true);
*/
public Q_SLOTS:
void dataUpdated(const QString&, const DataEngine::Data&);
Q_SIGNALS:
/**
* Indicates that this Plasma::CheckBox has been clicked, changing its state.
*/
void clicked();
protected:
//bool isDown();
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
void mouseMoveEvent (QGraphicsSceneMouseEvent * event);
void hoverMoveEvent ( QGraphicsSceneHoverEvent * event );
void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event );
void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
void init();
class Private ;
Private * const d;
};
} // namespace Plasma
#endif

View File

@ -1,150 +0,0 @@
/*
* Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 "label.h"
#include <QPainter>
#include <QFontMetricsF>
#include <QStyleOptionGraphicsItem>
namespace Plasma {
class Label::Private
{
public:
Private()
: maximumWidth(9999)
{}
QString text;
Qt::Alignment alignment;
QPen textPen;
QFont textFont;
int maximumWidth;
};
Label::Label(Widget *parent)
: Plasma::Widget(parent),
d(new Private)
{
setAlignment(Qt::AlignHCenter);
setPen(QPen(Qt::black, 1));
}
Label::~Label()
{
delete d;
}
Qt::Orientations Label::expandingDirections() const
{
return Qt::Horizontal | Qt::Vertical;
}
bool Label::hasHeightForWidth() const
{
return true;
}
qreal Label::heightForWidth(qreal w) const
{
Q_UNUSED( w );
//FIXME: this looks a bit odd?
QFontMetricsF m(d->textFont);
//return m.boundingRect(QRectF(0, 0, w, 9999), d->alignment | Qt::TextWordWrap, d->text).height();
return 0;
}
#ifdef REMOVE
QSizeF Label::sizeHint() const
{
QFontMetricsF m(d->textFont);
return m.boundingRect(QRectF(0,0,9999,9999), d->alignment | Qt::TextWordWrap, d->text).size();
//return m.boundingRect(QRectF(0, 0, d->maximumWidth, 9999), d->alignment | Qt::TextWordWrap, d->text).size();
}
#endif
void Label::setText(const QString& text)
{
d->text = text;
updateGeometry();
update();
}
QString Label::text() const
{
return d->text;
}
void Label::setAlignment(Qt::Alignment align)
{
d->alignment = align;
}
Qt::Alignment Label::alignment() const
{
return d->alignment;
}
void Label::setPen(const QPen& pen)
{
d->textPen = pen;
updateGeometry();
update();
}
QPen Label::pen() const
{
return d->textPen;
}
void Label::setMaximumWidth(int width)
{
d->maximumWidth = width;
}
int Label::maximumWidth() const
{
return d->maximumWidth;
}
void Label::setFont(const QFont& font)
{
d->textFont = font;
updateGeometry();
update();
}
QFont Label::font() const
{
return d->textFont;
}
void Label::paintWidget(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
p->setPen(d->textPen);
p->setFont(d->textFont);
p->drawText(option->rect, d->alignment | Qt::TextWordWrap, d->text);
}
}

View File

@ -1,145 +0,0 @@
/*
* Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 __PLASMA_LABEL__
#define __PLASMA_LABEL__
#include <plasma/widgets/widget.h>
#include <QtGui/QPen>
#include <QtGui/QFont>
class QGraphicsTextItem;
namespace Plasma
{
/**
* Simple Text Label.
*
* @author Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
*
* This class is a simple text label, it just draws plain text.
*/
class PLASMA_EXPORT Label : public Plasma::Widget
{
Q_OBJECT
Q_PROPERTY( QString text READ text WRITE setText )
Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
Q_PROPERTY( QPen pen READ pen WRITE setPen )
Q_PROPERTY( int maximumWidth READ maximumWidth WRITE setMaximumWidth )
public:
/**
* Constructor.
*/
Label(Widget *parent);
/**
* Virtual Destructor.
*/
virtual ~Label();
/**
* Labels can expand in Horizontal and Vertical directions.
*/
Qt::Orientations expandingDirections() const;
/**
* Labels can use height-for-width geometry management.
*/
bool hasHeightForWidth() const;
/**
* Reimplemented from Plasma::Widget.
*/
qreal heightForWidth(qreal w) const;
#ifdef REMOVE
/**
* Reimplemented from Plasma::Widget.
*/
QSizeF sizeHint() const;
#endif
/**
* Sets the text to be displayed.
*/
void setText(const QString& text);
/**
* Returns the displayed text.
*/
QString text() const;
/**
* Sets the alignment of the displayed text.
*/
void setAlignment(Qt::Alignment align);
/**
* Returns the alignment of the displayed text.
*/
Qt::Alignment alignment() const;
/**
* Sets the pen used to paint the text.
*/
void setPen(const QPen& pen);
/**
* Returns the pen used to paint the text.
*/
QPen pen() const;
/**
* Sets the maximum width that this label should extend to
*
* @arg width the new maximum width in pixels
*/
void setMaximumWidth(int width);
/**
* The width in pixels that this label is constrained to
*/
int maximumWidth() const;
/**
* Sets the font used for the text.
*/
void setFont(const QFont& font);
/**
* Returns the font used for the text.
*/
QFont font() const;
/**
* Paint function.
*/
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
class Private;
Private * const d;
};
}
#endif /* __PLASMA_LABEL__ */

View File

@ -1,303 +0,0 @@
/*
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 "lineedit.h"
#include <limits>
#include <QStyleOptionFrameV2>
#include <QTextDocument>
#include <QKeyEvent>
#include <QPainter>
#include <KDebug>
#include <KColorScheme>
#include <KApplication>
#include <plasma/theme.h>
#include "plasma/layouts/layout.h"
namespace Plasma
{
class LineEdit::Private
{
public:
Private()
: showingDefaultText(true), styled(true), multiline(false) {}
QString defaultText;
QString oldText;
bool showingDefaultText;
bool styled;
bool multiline;
};
LineEdit::LineEdit(QGraphicsItem *parent)
: QGraphicsTextItem(parent),
d(new Private())
{
setTextInteractionFlags(Qt::TextEditorInteraction);
setCursor(Qt::IBeamCursor);
setFlag(QGraphicsItem::ItemIsSelectable);
}
LineEdit::~LineEdit()
{
delete d;
}
void LineEdit::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (d->styled && 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<QStyleOptionGraphicsItem*>(option);
style->state &= ~(QStyle::State_Selected | QStyle::State_HasFocus);
QGraphicsTextItem::paint(painter, style, widget);
}
void LineEdit::dataUpdated(const QString&, const DataEngine::Data& data)
{
DataEngine::DataIterator it(data);
QString text;
while (it.hasNext()) {
it.next();
if (it.value().canConvert(QVariant::String)) {
text.append(QString("<p><b>%1</b>: %2</p>").arg(it.key(), it.value().toString()));
}
}
setHtml(text);
}
void LineEdit::setMultiLine(bool multi)
{
d->multiline = multi;
}
bool LineEdit::multiLine() const
{
return d->multiline;
}
void LineEdit::setStyled(bool style)
{
d->styled = style;
if (style) {
setDefaultTextColor(kapp->palette().color(QPalette::Text));
} else {
setDefaultTextColor(Plasma::Theme::self()->textColor());
}
}
bool LineEdit::styled() const
{
return d->styled;
}
Qt::Orientations LineEdit::expandingDirections() const
{
return Qt::Vertical;
}
QSizeF LineEdit::minimumSize() const
{
QSizeF sh = document()->size();
sh.setWidth(textWidth());
return sh;
}
QSizeF LineEdit::maximumSize() const
{
//TODO: well, this is useless, isn't it? ;) when ported to WoC, remove it
return QSizeF(std::numeric_limits<qreal>::infinity(),
std::numeric_limits<qreal>::infinity());
}
bool LineEdit::hasHeightForWidth() const
{
return true;
}
qreal LineEdit::heightForWidth(qreal w) const
{
QTextDocument* doc = document();
doc->setTextWidth(w);
qreal height = doc->size().height();
//kDebug() << "LineEdit::heightForWidth(" << w << ") is " << height;
return height;
}
bool LineEdit::hasWidthForHeight() const
{
return false;
}
qreal LineEdit::widthForHeight(qreal h) const
{
Q_UNUSED(h);
return 0;
}
QRectF LineEdit::geometry() const
{
return QRectF(pos(), boundingRect().size());
}
void LineEdit::setGeometry(const QRectF& geometry)
{
prepareGeometryChange();
QRectF geom(geometry.topLeft(),
geometry.size().boundedTo(maximumSize()).expandedTo(minimumSize()));
setTextWidth(geom.width());
setPos(geom.topLeft());
update();
}
void LineEdit::updateGeometry()
{
if (managingLayout()) {
managingLayout()->invalidate();
} else {
setGeometry(QRectF(pos(), sizeHint()));
}
}
QSizeF LineEdit::sizeHint() const
{
QSizeF sh = document()->size();
if (sh.width() < textWidth()) {
sh.setWidth(textWidth());
}
return sh;
}
void LineEdit::setDefaultText(const QString &text)
{
d->defaultText = text.simplified();
//FIXME hardcoded colours aren't nice
d->defaultText = QString("<font color=\"gray\">") + d->defaultText + QString("</font>");
if (d->showingDefaultText) {
QGraphicsTextItem::setHtml(d->defaultText);
}
}
const QString LineEdit::toHtml()
{
if (d->showingDefaultText) {
return QString();
} else {
return QGraphicsTextItem::toHtml();
}
}
const QString LineEdit::toPlainText()
{
if (d->showingDefaultText) {
return QString();
} else {
return QGraphicsTextItem::toPlainText();
}
}
void LineEdit::setHtml(const QString &text)
{
if (text.isEmpty()) {
d->showingDefaultText = true;
QGraphicsTextItem::setHtml(d->defaultText);
} else {
d->showingDefaultText = false;
QGraphicsTextItem::setHtml(text);
}
}
void LineEdit::setPlainText(const QString &text)
{
if (text.isEmpty()) {
d->showingDefaultText = true;
QGraphicsTextItem::setHtml(d->defaultText);
} else {
d->showingDefaultText = false;
QGraphicsTextItem::setPlainText(text);
}
}
void LineEdit::keyPressEvent(QKeyEvent *event)
{
if ( !d->multiline && (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)) {
emit editingFinished();
event->accept();
} else {
QGraphicsTextItem::keyPressEvent(event); //let QT handle other keypresses
}
if (QGraphicsTextItem::toHtml() != d->oldText) {
d->oldText = QGraphicsTextItem::toHtml();
emit textChanged(QGraphicsTextItem::toHtml());
}
// if (QGraphicsTextItem::toPlainText().simplified().isEmtpy())
// QGraphicsTextItem::setHtml(d->defaultText);
}
void LineEdit::focusInEvent(QFocusEvent *event)
{
if (d->showingDefaultText) {
QGraphicsTextItem::setHtml(QString());
d->showingDefaultText = false;
}
QGraphicsTextItem::focusInEvent(event);
}
void LineEdit::focusOutEvent(QFocusEvent *event)
{
if (QGraphicsTextItem::toPlainText().isEmpty()) {
QGraphicsTextItem::setHtml(d->defaultText);
d->showingDefaultText = true;
}
QGraphicsTextItem::focusOutEvent(event);
}
QPointF LineEdit::position() const
{
return pos();
}
} // namespace Plasma
#include "lineedit.moc"

View File

@ -1,112 +0,0 @@
/*
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 <QtCore/QObject>
#include <QtGui/QGraphicsTextItem>
#include <plasma/plasma_export.h>
#include <plasma/dataengine.h>
#include <plasma/plasma.h>
#include <plasma/layouts/layoutitem.h>
namespace Plasma
{
/**
* Class that emulates a QLineEdit inside plasma
*/
class PLASMA_EXPORT LineEdit : public QGraphicsTextItem, public LayoutItem
{
Q_OBJECT
Q_PROPERTY( bool styled READ styled WRITE setStyled )
Q_PROPERTY( bool multiLine READ multiLine WRITE setMultiLine )
Q_PROPERTY( QString defaultText WRITE setDefaultText )
Q_PROPERTY( QString html READ toHtml )
Q_PROPERTY( QString plainText READ toPlainText )
public:
explicit LineEdit(QGraphicsItem *parent = 0);
~LineEdit();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
Qt::Orientations expandingDirections() const;
QSizeF minimumSize() const;
QSizeF maximumSize() const;
void setStyled(bool style);
bool styled() const;
void setMultiLine(bool multi);
bool multiLine() const;
bool hasHeightForWidth() const;
qreal heightForWidth(qreal w) const;
bool hasWidthForHeight() const;
qreal widthForHeight(qreal h) const;
QRectF geometry() const;
void setGeometry(const QRectF& geometry);
void updateGeometry();
QSizeF sizeHint() const;
/**
* Set text to be displayed when the LineEdit is empty and doesn't have focus.
*/
void setDefaultText(const QString &text);
const QString toHtml();
const QString toPlainText();
void setHtml(const QString &text);
void setPlainText(const QString &text);
/**
* Reimplented from QGraphicsItem
**/
enum { Type = Plasma::LineEditType };
int type() const { return Type; }
Q_SIGNALS:
void editingFinished();
void textChanged(const QString &text);
public Q_SLOTS:
void dataUpdated(const QString&, const Plasma::DataEngine::Data&);
private:
class Private;
Private* const d;
protected:
void keyPressEvent(QKeyEvent *event);
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
QPointF position() const;
};
} // namespace Plasma
#endif

View File

@ -1,258 +0,0 @@
/*
* Copyright (C) 2007 Jon de Andres Frias <jondeandres@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 "progressbar.h"
#include <QWidget>
#include <QStyleOptionProgressBarV2>
#include <QPainter>
#include <QStyle>
#include <QtGlobal>
#include <QApplication>
#include <kdebug.h>
namespace Plasma
{
class ProgressBar::Private
{
public:
Private() {}
~Private() {}
QString format;
QString text;
Qt::Alignment alignment;
bool invertedAppearance;
bool textVisible;
int maximum;
int minimum;
int value;
int lastPaintedValue;
};
ProgressBar::ProgressBar(Widget *parent)
: Plasma::Widget(parent),
d(new Private)
{
init();
}
ProgressBar::~ProgressBar()
{
delete d;
}
void ProgressBar::init()
{
setAlignment(Qt::AlignLeft);
setFormat(QLatin1String("%p%"));
setInvertedAppearance(false);
setTextVisible(true);
setMinimum(0);
setMaximum(100);
setValue(-1);
d->lastPaintedValue = -1;
}
void ProgressBar::setAlignment(Qt::Alignment alignment)
{
if (d->alignment != alignment) {
d->alignment = alignment;
update();
}
}
Qt::Alignment ProgressBar::alignment() const
{
return d->alignment;
}
void ProgressBar::setFormat(const QString &format)
{
if (d->format != format) {
d->format = format;
update();
}
}
QString ProgressBar::format() const
{
return d->format;
}
void ProgressBar::setInvertedAppearance(bool invert)
{
if (d->invertedAppearance & invert) {
return;
}
d->invertedAppearance = invert;
update();
}
bool ProgressBar::invertedAppearance()
{
return d->invertedAppearance;
}
void ProgressBar::setTextVisible(bool visible)
{
if (d->textVisible & visible) {
return;
}
d->textVisible = visible;
}
bool ProgressBar::isTextVisible() const
{
return d->textVisible;
}
void ProgressBar::reset()
{
d->value = d->minimum - 1;
update();
}
void ProgressBar::setRange(int minimum, int maximum)
{
d->minimum = minimum;
d->maximum = maximum;
if (d->value < (d->minimum - 1) || d->value > d->maximum) {
reset();
}
}
void ProgressBar::setMinimum(int minimum)
{
setRange(minimum, qMax(d->maximum, minimum));
}
void ProgressBar::setMaximum(int maximum)
{
setRange(qMin(d->minimum, maximum), maximum);
}
int ProgressBar::maximum() const
{
return d->maximum;
}
int ProgressBar::minimum() const
{
return d->minimum;
}
void ProgressBar::setValue(int value)
{
//This line is from qprogressbar.cpp by Qt.
if (d->value == value
|| ((value > d->maximum || value < d->minimum)
&& (d->maximum != 0 || d->minimum != 0)))
return;
d->value = value;
emit valueChanged(value);
update();
}
int ProgressBar::value() const
{
return d->value;
}
void ProgressBar::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyle *style = widget ? widget->style() : QApplication::style();
QStyleOptionProgressBarV2 options;
options.minimum = d->minimum;
options.maximum = d->maximum;
options.progress = d->value;
options.textAlignment = d->alignment;
options.textVisible = d->textVisible;
options.text = text();
options.invertedAppearance = d->invertedAppearance;
options.rect = option->rect;
style->drawControl(QStyle::CE_ProgressBar, &options, painter, widget);
}
QSizeF ProgressBar::sizeHint() const
{
QFontMetrics fm(font());
QStyleOptionProgressBarV2 options;
options.minimum = d->minimum;
options.maximum = d->maximum;
options.progress = d->value;
options.textAlignment = d->alignment;
options.textVisible = d->textVisible;
options.text = text();
options.invertedAppearance = d->invertedAppearance;
QStyle *style = QApplication::style();
int cw = style->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &options);
QSize size = QSize(cw * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8);
return style->sizeFromContents(QStyle::CT_ProgressBar, &options, size);
}
/*This method has the same code that QProgressBar::text() */
QString ProgressBar::text() const
{
qint64 totalSteps = qint64(d->maximum) - qint64(d->minimum);
QString result = d->format;
result.replace(QLatin1String("%m"), QString::fromLatin1("%1").arg(totalSteps));
result.replace(QLatin1String("%v"), QString::fromLatin1("%1").arg(d->value));
if (totalSteps == 0) {
result.replace(QLatin1String("%p"), QString::fromLatin1("%1").arg(100));
return result;
}
int progress = int(((qreal(d->value) - qreal(d->minimum)) * 100.0) / totalSteps);
result.replace(QLatin1String("%p"), QString::fromLatin1("%1").arg(progress));
return result;
}
}
#include "progressbar.moc"

View File

@ -1,144 +0,0 @@
/*
* Copyright (C) 2007 Jon de Andres Frias <jondeandres@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 __PLASMA_PROGRESSBAR__
#define __PLASMA_PROGRESSBAR__
#include <plasma/widgets/widget.h>
namespace Plasma
{
class PLASMA_EXPORT ProgressBar : public Plasma::Widget
{
Q_OBJECT
Q_PROPERTY(QString format READ format WRITE setFormat)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance)
Q_PROPERTY(bool textVisible READ isTextVisible WRITE setTextVisible)
Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY(int value READ value WRITE setValue)
public:
/**
* Constructor
*/
ProgressBar(Widget *parent);
/**
* Virtual Destructor
*/
virtual ~ProgressBar();
/**
* @return alignment of the progressbar
*/
Qt::Alignment alignment() const;
/**
* @return the format for the shown text
*/
QString format() const;
/**
* @return whether the Plasma::ProgressBar is inverted or not.
*/
bool invertedAppearance();
/**
* @return whether the text is visible or not.
*/
bool isTextVisible() const;
/**
* @return the maximum value in the range of Plasma::ProgressBar
*/
int maximum() const;
/**
* @return the minimum value in the range of Plasma:ProgressBar
*/
int minimum() const;
/**
* Changes the alignment of Plasma::ProgressBar
*
* %p - is replaced by the percentage completed
* %v - is replaced by the current value
* %m - is replaced by the total number of steps
* @param alignment the alignment for the progressbar.
*/
void setAlignment(Qt::Alignment alignment);
/**
* Sets the format for the shown text in Plasma::ProgressBar;
* @format the format for the shown text in Plasma:ProgressBar
*/
void setFormat(const QString &format);
/**
* Inverts the appearance of Plasma::ProgressBar
* @param invert true inverts the appearance
*/
void setInvertedAppearance(bool invert);
/**
* Change the text to be visible or not.
* @param visible if true then visible
*/
void setTextVisible(bool visible);
/**
* @return the text to be shown in Plasma::ProgressBar
*/
QString text() const;
/**
* @return the actual value of the progress
*/
int value() const;
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
QSizeF sizeHint() const;
public Q_SLOTS:
void reset();
void setRange(int minimum, int maximum);
void setMinimum(int minimum);
void setMaximum(int maximum);
void setValue(int value);
Q_SIGNALS:
void valueChanged(int value);
private:
void init();
class Private;
Private * const d;
};
}
#endif /*__PLASMA_PROGRESSBAR__*/

View File

@ -1,324 +0,0 @@
/*
* Copyright 2007 by Siraj Razick <siraj@kde.org>
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 "pushbutton.h"
#include <QStylePainter>
#include <QStyleOptionButton>
#include <QStyle>
#include <QWidget>
#include <QPainter>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QFontMetricsF>
#include <QApplication>
namespace Plasma
{
class PushButton::Private
{
public:
enum ButtonShape
{
Rectangle = 0,
Round,
Custom
};
enum ButtonState
{
None,
Hover,
Pressed,
Released
};
public:
Private()
: flat(false),
checkable(false),
checked(false),
state(None)
{}
void init(PushButton *button);
void initStyleOption(QStyleOptionButton *option, const PushButton *button,
const QStyleOptionGraphicsItem *graphicsOption = 0 ) const;
QString text;
KIcon icon;
QSizeF iconSize;
bool flat;
bool checkable;
bool checked;
ButtonState state;
};
void PushButton::Private::init(PushButton *button)
{
button->setAcceptedMouseButtons(Qt::LeftButton);
button->setAcceptsHoverEvents(true);
button->setEnabled(true);
}
void PushButton::Private::initStyleOption(QStyleOptionButton *option, const PushButton *button,
const QStyleOptionGraphicsItem *graphicsOption) const
{
option->state = QStyle::State_None;
if (button->isEnabled()) {
option->state |= QStyle::State_Enabled;
}
if (button->hasFocus()) {
option->state |= QStyle::State_HasFocus;
}
if (state == Private::Hover) {
option->state |= QStyle::State_MouseOver;
}
if (graphicsOption) {
option->palette = graphicsOption->palette;
option->fontMetrics = graphicsOption->fontMetrics;
option->rect = graphicsOption->rect;
} else {
option->palette = QApplication::palette(); // pretty good guess
option->fontMetrics = QApplication::fontMetrics(); // hrm
}
option->features = QStyleOptionButton::None;
if (flat) {
option->features |= QStyleOptionButton::Flat;
}
if (!flat && !(checked || state == Private::Pressed)) {
option->state |= QStyle::State_Raised;
} else {
option->state |= QStyle::State_Sunken;
}
option->text = text;
option->icon = icon;
option->iconSize = button->iconSize().toSize();
}
PushButton::PushButton(Widget *parent)
: Plasma::Widget(parent),
d(new Private)
{
d->init(this);
}
PushButton::PushButton(const QString &text, Widget *parent)
: Plasma::Widget(parent),
d(new Private)
{
d->init(this);
setText(text);
}
PushButton::PushButton(const KIcon &icon, const QString &text, Widget *parent)
: Plasma::Widget(parent),
d(new Private)
{
d->init(this);
setText(text);
setIcon(icon);
}
PushButton::~PushButton()
{
delete d;
}
void PushButton::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *widget)
{
QStyleOptionButton option;
if (widget) {
option.initFrom(widget);
}
d->initStyleOption(&option, this, opt);
QApplication::style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &option, painter, widget);
QApplication::style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, painter, widget);
QApplication::style()->drawControl(QStyle::CE_PushButton, &option, painter, widget);
}
void PushButton::setText(const QString& text)
{
d->text = text;
update();
}
QString PushButton::text() const
{
return d->text;
}
void PushButton::setIcon(const KIcon &icon)
{
d->icon = icon;
update();
}
void PushButton::setIcon(const QString &path)
{
KIcon icon(path);
setIcon(icon);
}
KIcon PushButton::icon() const
{
return d->icon;
}
QSizeF PushButton::iconSize() const
{
if (d->iconSize.isValid())
return d->iconSize;
qreal metric = qreal(QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize));
return QSizeF(metric, metric);
}
void PushButton::setIconSize(const QSizeF &size)
{
if (d->iconSize == size)
return;
d->iconSize = size;
update();
}
bool PushButton::isDown() const
{
return (d->state == Private::Pressed);
}
bool PushButton::isFlat() const
{
return d->flat;
}
void PushButton::setFlat(bool flat)
{
d->flat = flat;
update();
}
bool PushButton::isChecked() const
{
return d->checked;
}
void PushButton::setChecked(bool checked)
{
if (isCheckable()) {
d->checked = checked;
update();
}
}
bool PushButton::isCheckable() const
{
return d->checkable;
}
void PushButton::setCheckable(bool checkable)
{
d->checkable = checkable;
}
void PushButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
d->state = Private::Pressed;
update();
}
void PushButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (sceneBoundingRect().contains(event->scenePos())) {
if (d->state == Private::Released && scene()->mouseGrabberItem() == this) {
d->state = Private::Pressed;
update();
}
} else {
if (d->state == Private::Pressed) {
d->state = Private::Released;
update();
}
}
}
void PushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (d->state == Private::Pressed) {
d->state = Private::Released;
emit clicked();
if (d->checkable) {
d->checked = ! d->checked;
emit toggled(d->checked);
}
update();
}
}
QSizeF PushButton::minimumSize() const
{
QFontMetricsF m = qApp->fontMetrics();
return m.boundingRect(text()).size() + QSizeF(5.0f, 5.0f);
}
Qt::Orientations PushButton::expandingDirections() const
{
return Qt::Horizontal;
}
#ifdef REMOVE
QSizeF PushButton::sizeHint() const
{
int width = 0;
int height = 0;
QStyleOptionButton option;
d->initStyleOption(&option, this);
if (!icon().isNull()) {
height += qMax(option.iconSize.height(), height);
width += 2 + option.iconSize.width() + 2; // add margin
}
QString display(option.text);
QSize textSize = option.fontMetrics.size(Qt::TextShowMnemonic, display);
width += textSize.width();
height = qMax(height, textSize.height());
return QSizeF((QApplication::style()->sizeFromContents(QStyle::CT_PushButton, &option, QSize(width, height), 0).
expandedTo(QApplication::globalStrut())));
}
#endif
} // namespace Plasma
#include "pushbutton.moc"

View File

@ -1,196 +0,0 @@
/*
* Copyright 2007 by Siraj Razick <siraj@kde.org>
* Copyright 2007 by Matias Valdenegro <mvaldenegro@informatica.utem.cl>
* Copyright 2007 by Matt Broadstone <mbroadst@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 PUSHBUTTON_H
#define PUSHBUTTON_H
#include <QtCore/QObject>
#include <QtGui/QGraphicsTextItem>
#include <QtGui/QLayoutItem>
#include <KDE/KIcon>
#include <plasma/dataengine.h>
#include <plasma/widgets/widget.h>
#include <plasma/plasma_export.h>
class QStyleOptionButton;
namespace Plasma
{
/**
* Class that emulates a QPushButton inside Plasma
*
* @author Siraj Razick
* @author Matias Valdenegro
* @author Matt Broadstone
*
*
*/
class PLASMA_EXPORT PushButton : public Plasma::Widget
{
Q_OBJECT
Q_PROPERTY( QString text READ text WRITE setText )
Q_PROPERTY( QSizeF iconSize READ iconSize WRITE setIconSize )
Q_PROPERTY( KIcon icon READ icon WRITE setIcon )
Q_PROPERTY( bool flat READ isFlat WRITE setFlat )
Q_PROPERTY( bool checkable READ isCheckable WRITE setCheckable )
Q_PROPERTY( bool checked READ isChecked WRITE setChecked)
public:
/**
* Creates a new Plasma::PushButton.
* @param parent the Widge this button is parented to.
*/
explicit PushButton(Widget *parent = 0);
/**
* Creates a new Plasma::PushButton with a text label.
* @param text the text to display next to the button.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit PushButton(const QString &text, Widget *parent = 0);
/**
* Creates a new Plasma::PushButton with an icon and text
* @param icon the icon to display with this button.
* @param text the text to display with this button.
* @param parent the QGraphicsItem this icon is parented to.
*/
explicit PushButton(const KIcon &icon, const QString &text, Widget *parent = 0);
/**
* Destroys this Plasma::PushButton.
*/
virtual ~PushButton();
/**
* @return text associated with this Plasma::PushButton
*/
QString text() const;
/**
* Sets the text to be displayed by this button.
* @param text the text to display
*/
void setText(const QString &text);
/**
* @return the icon displayed by this button.
*/
KIcon icon() const;
/**
* Sets the icon to be displayed by this Plasma::Icon.
* @param icon the KIcon to display.
*/
void setIcon(const KIcon &icon);
/**
* Convenience method to set the icon of this Plasma::PushButton
* based on the icon path, or name.
* @see KIconLoader
* @param path the path to, or name of the icon to display.
*/
Q_INVOKABLE void setIcon(const QString& path);
/**
* @return the size of the icon displayed by this Plasma::PushButton.
*/
QSizeF iconSize() const;
/**
* Sets the size of icon shown by this button.
* @param size size of the icon.
*/
void setIconSize(const QSizeF &size);
/**
* @return whether this button is currently in a down/pressed state.
*/
bool isDown() const;
/**
* @return whether this button is drawn flat.
*/
bool isFlat() const;
/**
* Sets whether the button is drawn flat.
* @param flat whether to draw it flat or not.
*/
void setFlat(bool flat);
/**
* @return whether this button is checkable.
*/
bool isCheckable() const;
/**
* Sets whether the button is checkable.
* @param checkable whether button is checkable or not.
*/
void setCheckable(bool checkable);
/**
* @return whether this button is checked.
*/
bool isChecked() const;
/**
* Sets whether the button is checked.
* @param checked whether button is checked or not.
*/
void setChecked(bool checked);
// NOTE: bogus
QSizeF minimumSize() const;
Qt::Orientations expandingDirections() const;
#ifdef REMOVE
QSizeF sizeHint() const;
#endif
Q_SIGNALS:
/**
* Triggered when the button has been clicked.
*/
void clicked();
/**
* Triggered when the checkable button has been toggled.
*/
void toggled(bool checked);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
class Private ;
Private * const d;
};
} // namespace Plasma
#endif

View File

@ -1,218 +0,0 @@
/*
* Copyright 2007 by Rafael Fernández López <ereslibre@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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.
*/
// Header Includes
#include "radiobutton.h"
// Qt includes
#include <QtGui/QWidget>
#include <QtGui/QApplication>
#include <QtGui/QGraphicsScene>
#include <QtGui/QStyleOptionButton>
#include <QtGui/QGraphicsSceneMouseEvent>
namespace Plasma
{
/// Private section ==============================
class RadioButton::Private
{
public:
Private();
~Private();
// Attributes
bool checked;
bool mouseOver;
bool mouseDown;
QString text;
};
RadioButton::Private::Private()
: checked(false)
, mouseOver(false)
, mouseDown(false)
, text(QString())
{
}
RadioButton::Private::~Private()
{
}
/// End Private section ==========================
RadioButton::RadioButton(QGraphicsItem *parent)
: Plasma::Widget(parent),
d(new Private)
{
setAcceptedMouseButtons(Qt::LeftButton);
setAcceptsHoverEvents(true);
}
RadioButton::~RadioButton()
{
delete d;
}
QRectF RadioButton::boundingRect() const
{
return QRectF(0, 0, 150, 30); // FIXME: this is obviously wrong
}
void RadioButton::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyle *style = widget ? widget->style() : QApplication::style();
QStyleOptionButton radioButtonOption;
radioButtonOption.rect = option->rect;
radioButtonOption.text = d->text;
radioButtonOption.state = option->state;
radioButtonOption.state |= d->checked ? QStyle::State_On : QStyle::State_Off;
radioButtonOption.state |= d->mouseOver ? QStyle::State_MouseOver : QStyle::State_None;
radioButtonOption.state |= d->mouseDown ? QStyle::State_Sunken : QStyle::State_Raised;
style->drawControl(QStyle::CE_RadioButton, &radioButtonOption, painter, widget);
}
bool RadioButton::isChecked() const
{
return d->checked;
}
const QString &RadioButton::text() const
{
return d->text;
}
void RadioButton::setChecked(bool checked)
{
RadioButton *siblingRadioButton;
// If we have a parent item (some kind of grouping widget or whatever)
// check first there
if (d->mouseOver && checked && parentItem())
{
foreach(QGraphicsItem *sibling, parentItem()->children())
{
siblingRadioButton = dynamic_cast<RadioButton*>(sibling);
if (siblingRadioButton && siblingRadioButton->isChecked())
{
siblingRadioButton->setChecked(false);
break; // Only an item is checked at same time as maximum
}
}
}
else if (checked && !parentItem() && scene())
{
// we should be on a scene, not flying anywhere
foreach(QGraphicsItem *sibling, scene()->items())
{
siblingRadioButton = dynamic_cast<RadioButton*>(sibling);
if (siblingRadioButton && siblingRadioButton->isChecked() && !siblingRadioButton->parentItem())
{
siblingRadioButton->setChecked(false);
break; // Only an item is checked at same time as maximum
}
}
}
d->checked = checked;
update();
}
void RadioButton::setText(const QString &text)
{
d->text = text;
update();
}
void RadioButton::dataUpdated(const QString&, const Plasma::DataEngine::Data &data)
{
DataEngine::DataIterator it(data);
while (it.hasNext()) {
it.next();
if (it.value().canConvert(QVariant::Bool)) {
setChecked(it.value().toBool());
return;
}
}
}
void RadioButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
d->mouseDown = true;
update();
}
void RadioButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
d->mouseDown = false;
if (sceneBoundingRect().contains(event->scenePos())) {
setChecked(true);
emit clicked();
}
update();
}
void RadioButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
d->mouseOver = true;
update();
}
void RadioButton::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
d->mouseOver = true;
update();
}
void RadioButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
d->mouseOver = false;
update();
Widget::hoverLeaveEvent(event);
}
void RadioButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
d->mouseOver = true;
update();
Widget::hoverEnterEvent(event);
}
} // Plasma namespace
#include "radiobutton.moc"

View File

@ -1,95 +0,0 @@
/*
* Copyright 2007 by Rafael Fernández López <ereslibre@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 RADIOBUTTON_H
#define RADIOBUTTON_H
// Qt includes
#include <QtCore/QObject>
#include <QtGui/QGraphicsItem>
// KDE includes
#include <plasma/plasma_export.h>
#include <plasma/widgets/widget.h>
#include <plasma/dataengine.h>
namespace Plasma
{
/**
* This class emulates a QRadioButton.
*
* You will be able to add radio buttons as childrens of a QGraphicsItem, so
* only one radio button will be checked at a time. If you don't add them as
* siblings (adding all them as childrens of the same QGraphicsItem), then
* you can add them directly to a scene, where they will be siblings too. This
* way you can have groups of radio buttons.
*
* @note Please before working with radio buttons, add them to a scene or as
* childrens of another QGraphicsItem.
*
* @author Rafael Fernández López
*/
class PLASMA_EXPORT RadioButton : public Plasma::Widget
{
Q_OBJECT
Q_PROPERTY( QString text READ text WRITE setText )
Q_PROPERTY( bool checked READ isChecked WRITE setChecked )
public:
RadioButton(QGraphicsItem *parent = 0);
virtual ~RadioButton();
// QGraphicsItem overridden virtual methods
QRectF boundingRect() const;
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
// Getters
bool isChecked() const;
const QString &text() const;
// Setters
void setChecked(bool checked);
void setText(const QString &text);
public Q_SLOTS:
void dataUpdated(const QString&, const Plasma::DataEngine::Data &data);
Q_SIGNALS:
void clicked();
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
private:
class Private;
Private *const d;
};
} // Plasma namespace
#endif // RADIOBUTTON_H