[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1682: Add an initial attempt at a VClickLabel class that creates a (in trunk: . src/gui/common)
Author: edmanm
Date: 2007-03-18 22:42:50 -0400 (Sun, 18 Mar 2007)
New Revision: 1682
Added:
trunk/src/gui/common/vclicklabel.cpp
trunk/src/gui/common/vclicklabel.h
Modified:
trunk/
trunk/src/gui/common/common.pri
Log:
r1745@adrastea: edmanm | 2007-03-18 22:31:24 -0400
Add an initial attempt at a VClickLabel class that creates a clickable label
that can have both an image and text.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r1745] on 54b3572a-7227-0410-958f-53ecd705b71a
Modified: trunk/src/gui/common/common.pri
===================================================================
--- trunk/src/gui/common/common.pri 2007-03-19 02:42:43 UTC (rev 1681)
+++ trunk/src/gui/common/common.pri 2007-03-19 02:42:50 UTC (rev 1682)
@@ -22,8 +22,10 @@
#################################################################
HEADERS += $$PWD/vidaliawindow.h \
- $$PWD/vmessagebox.h
+ $$PWD/vmessagebox.h \
+ $$PWD/vclicklabel.h
SOURCES += $$PWD/vidaliawindow.cpp \
- $$PWD/vmessagebox.cpp
+ $$PWD/vmessagebox.cpp \
+ $$PWD/vclicklabel.cpp
Added: trunk/src/gui/common/vclicklabel.cpp
===================================================================
--- trunk/src/gui/common/vclicklabel.cpp (rev 0)
+++ trunk/src/gui/common/vclicklabel.cpp 2007-03-19 02:42:50 UTC (rev 1682)
@@ -0,0 +1,94 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2006, Matt Edman, Justin Hipple
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, 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 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.
+ ****************************************************************/
+
+/**
+ * \file vclicklabel.cpp
+ * \version $Id$
+ * \brief Custom widget to create a clickable label with both an image and text.
+ */
+
+#include <QPainter>
+
+#include "vclicklabel.h"
+
+
+/** Default constructor. */
+VClickLabel::VClickLabel(QWidget *parent)
+ : QWidget(parent)
+{
+ setCursor(Qt::PointingHandCursor);
+}
+
+/** Returns the current size hint for this widget's current contents. */
+QSize
+VClickLabel::sizeHint() const
+{
+ int height = qMax(_pixmap.height(), fontMetrics().height())+2;
+ int width = _pixmap.width() + fontMetrics().width(_text)+2;
+ return QSize(width, height);
+}
+
+/** Returns the minimum size hint for this widget's current contents. */
+QSize
+VClickLabel::minimumSizeHint() const
+{
+ return sizeHint();
+}
+
+/** Overloaded paint event to draw a pixmap and a text label. */
+void
+VClickLabel::paintEvent(QPaintEvent *e)
+{
+ QPainter p(this);
+ QRect rect = this->rect();
+ if (!_pixmap.isNull())
+ p.drawPixmap(0, qMax((rect.height()-_pixmap.height())/2,0), _pixmap);
+ if (!_text.isEmpty())
+ p.drawText(_pixmap.width()+2, (rect.height()+fontInfo().pixelSize())/2, _text);
+ e->accept();
+}
+
+/** Overloaded mouse event to catch left mouse button clicks. */
+void
+VClickLabel::mouseReleaseEvent(QMouseEvent *e)
+{
+ if (e->button() == Qt::LeftButton) {
+ emit clicked();
+ }
+ e->accept();
+}
+
+/** Sets the label text to <b>text</b>. */
+void
+VClickLabel::setText(const QString &text)
+{
+ _text = text;
+ update();
+}
+
+/** Sets the widget's image to <b>img</b>. */
+void
+VClickLabel::setPixmap(const QPixmap &pixmap)
+{
+ _pixmap = pixmap;
+ update();
+}
+
Property changes on: trunk/src/gui/common/vclicklabel.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/src/gui/common/vclicklabel.h
===================================================================
--- trunk/src/gui/common/vclicklabel.h (rev 0)
+++ trunk/src/gui/common/vclicklabel.h 2007-03-19 02:42:50 UTC (rev 1682)
@@ -0,0 +1,71 @@
+/****************************************************************
+ * Vidalia is distributed under the following license:
+ *
+ * Copyright (C) 2006, Matt Edman, Justin Hipple
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, 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 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.
+ ****************************************************************/
+
+/**
+ * \file vclicklabel.h
+ * \version $Id$
+ * \brief Custom widget to create a clickable label with both an image and text.
+ */
+
+#ifndef _VCLICKLABEL_H
+#define _VCLICKLABEL_H
+
+#include <QWidget>
+#include <QPixmap>
+#include <QMouseEvent>
+#include <QSize>
+
+
+class VClickLabel : public QWidget
+{
+ Q_OBJECT
+
+public:
+ /** Default constructor. */
+ VClickLabel(QWidget *parent = 0);
+
+ /** Returns the current size hint for this widget's current contents. */
+ virtual QSize sizeHint() const;
+ /** Returns the minimum size hint for this widget's current contents. */
+ virtual QSize minimumSizeHint() const;
+
+ /** Sets the label text to <b>text</b>. */
+ void setText(const QString &text);
+ /** Sets the widget's image to <b>img</b>. */
+ void setPixmap(const QPixmap &img);
+
+signals:
+ /** Emitted when the widget is left-clicked. */
+ void clicked();
+
+protected:
+ /** Overloaded paint event to draw a pixmap and a text label. */
+ virtual void paintEvent(QPaintEvent *e);
+ /** Overloaded mouse event to catch left mouse button clicks. */
+ virtual void mouseReleaseEvent(QMouseEvent *e);
+
+private:
+ QString _text; /**< Text label to display in the widget. */
+ QPixmap _pixmap; /**< Image to display in the widget. */
+};
+
+#endif
+
Property changes on: trunk/src/gui/common/vclicklabel.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native