Thread: SF.net SVN: fclient: [604] trunk/fclient/src/fclient/lib
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-13 09:42:55
|
Revision: 604
http://fclient.svn.sourceforge.net/fclient/?rev=604&view=rev
Author: jUrner
Date: 2008-07-13 02:43:02 -0700 (Sun, 13 Jul 2008)
Log Message:
-----------
reorganisation of qt4ex
Added Paths:
-----------
trunk/fclient/src/fclient/lib/qt4ex/
trunk/fclient/src/fclient/lib/qt4ex/LICENCE.MIT
trunk/fclient/src/fclient/lib/qt4ex/README
trunk/fclient/src/fclient/lib/qt4ex/__init__.py
trunk/fclient/src/fclient/lib/qt4ex/areatips.py
trunk/fclient/src/fclient/lib/qt4ex/checkarraywrap.py
trunk/fclient/src/fclient/lib/qt4ex/colorbutton.py
trunk/fclient/src/fclient/lib/qt4ex/dlgabout.py
trunk/fclient/src/fclient/lib/qt4ex/dlgfindreplace.py
trunk/fclient/src/fclient/lib/qt4ex/dlgpreferences.py
trunk/fclient/src/fclient/lib/qt4ex/dragtool.py
trunk/fclient/src/fclient/lib/qt4ex/editboxwrap.py
trunk/fclient/src/fclient/lib/qt4ex/labelwrap.py
trunk/fclient/src/fclient/lib/qt4ex/lang/
trunk/fclient/src/fclient/lib/qt4ex/lang/qt4ex_de.ts
trunk/fclient/src/fclient/lib/qt4ex/lang/qt4ex_en.ts
trunk/fclient/src/fclient/lib/qt4ex/lib/
trunk/fclient/src/fclient/lib/qt4ex/lib/__init__.py
trunk/fclient/src/fclient/lib/qt4ex/lib/assistant.py
trunk/fclient/src/fclient/lib/qt4ex/lib/language.py
trunk/fclient/src/fclient/lib/qt4ex/lib/resources.py
trunk/fclient/src/fclient/lib/qt4ex/lib/settings.py
trunk/fclient/src/fclient/lib/qt4ex/lib/tools.py
trunk/fclient/src/fclient/lib/qt4ex/mrumenu.py
trunk/fclient/src/fclient/lib/qt4ex/res/
trunk/fclient/src/fclient/lib/qt4ex/scripts/
trunk/fclient/src/fclient/lib/qt4ex/scripts/__init__.py
trunk/fclient/src/fclient/lib/qt4ex/scripts/manifest.py
trunk/fclient/src/fclient/lib/qt4ex/scripts/pylupdate.py
trunk/fclient/src/fclient/lib/qt4ex/scripts/qtpro.py
trunk/fclient/src/fclient/lib/qt4ex/tablewidget.py
trunk/fclient/src/fclient/lib/qt4ex/toolbarwrap.py
trunk/fclient/src/fclient/lib/qt4ex/tpls/
trunk/fclient/src/fclient/lib/qt4ex/tpls/DlgAbout.ui
trunk/fclient/src/fclient/lib/qt4ex/tpls/DlgFindReplace.ui
trunk/fclient/src/fclient/lib/qt4ex/tpls/DlgPreferencesTree.ui
trunk/fclient/src/fclient/lib/qt4ex/tpls/Ui_DlgAbout.py
trunk/fclient/src/fclient/lib/qt4ex/tpls/Ui_DlgFindReplace.py
trunk/fclient/src/fclient/lib/qt4ex/tpls/Ui_DlgPreferencesTree.py
trunk/fclient/src/fclient/lib/qt4ex/tpls/__init__.py
trunk/fclient/src/fclient/lib/qt4ex/treewidgetwrap.py
Added: trunk/fclient/src/fclient/lib/qt4ex/LICENCE.MIT
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/LICENCE.MIT (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/LICENCE.MIT 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,21 @@
+
+qt4ex -- Qt5 / PyQt4 extensions
+
+Copyright (c) 2007 J\xFCrgen Urner
+
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+and associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial
+portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
Added: trunk/fclient/src/fclient/lib/qt4ex/README
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/README (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/README 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,30 @@
+ qt4ex -- Qt5 / PyQt4 extensions
+
+
+
+Version history:
+
+
+*******************************************************************
+0.2.0
+*******************************************************************
+complete reorganisation of the package. too many changes to list here
+
+
+*******************************************************************
+0.1.0
+*******************************************************************
+news:
+ x. initial release
+
+bugfixes:
+ x.
+
+
+
+
+
+
+
+
+
Added: trunk/fclient/src/fclient/lib/qt4ex/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/__init__.py (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/__init__.py 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,11 @@
+"""Qt4 extensions
+
+"""
+
+__version__ = '0.2.0'
+__author__ = 'Juergen Urner'
+__emeil__ = 'jU...@ar...'
+__licence__ = 'Mit'
+__copyright__ = '(c) 2007-2008 Juergen Urner'
+
+
Added: trunk/fclient/src/fclient/lib/qt4ex/areatips.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/areatips.py (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/areatips.py 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,463 @@
+# -*- coding: utf-8 -*-
+
+"""Customized tooltips
+"""
+
+# TODO:
+#
+# x. fix ComboBoxEditTip to act as promised
+# x. add classes to handle temTips for editBoxes (...)
+#
+# x. ComboBox trouble.
+#
+# XXX jopefuly fixed by adding an event.type().Leave handler to cancel toolTip display XXX
+#
+# y. The dropdown of a combobox does not seem to eat up events
+# An itemView underneath the dropdown still receives mouseMove events
+# and may pop up an itemTip. No idea what todo.
+#
+# y. there is a glitch with comboBoxes. When an itemTip is popped up
+# and the user clicks on it, the dropDown is closed, but the itemTip
+# not. For some reason the itemView eats the mouse message and
+# the itemTip never gets notified.
+#
+# x. there is a possible glitch aswell in itemTips when an itemView gets
+# disabled / hidden while an itemTip is scheduled for display. No way to
+# cancel the itemTip currently
+#
+#
+import os
+from PyQt4 import QtCore, QtGui
+#***************************************************************************
+#
+#***************************************************************************
+DEFAULT_SHOW_DELAY = 400
+
+#***************************************************************************
+#
+#***************************************************************************
+#code for the toolTip is taken from QToolTip.cpp
+
+class AreaTip(QtGui.QLabel):
+ """
+ Customized tooltip class to show tooltips for a specified area
+ under the mouse cursor.
+
+ """
+
+ def __init__(self, parent, showDelay=DEFAULT_SHOW_DELAY):
+ """constructor
+
+ @param parent parent of the tooltip
+ @showDelay delay in milliseconds before the tootliptp is shown
+ """
+
+
+ QtGui.QLabel.__init__(self, parent, QtCore.Qt.ToolTip)
+ self.hide()
+
+
+ self._currentAreaTipData = None
+ self._showTimer = QtCore.QTimer(self)
+ self._showDelay = showDelay
+
+ self.connect(
+ self._showTimer,
+ QtCore.SIGNAL("timeout()"),
+ self.onShowTip)
+
+
+
+ self.ensurePolished()
+ frameW = self.style().pixelMetric(
+ QtGui.QStyle.PM_ToolTipLabelFrameWidth,
+ None,
+ self
+ )
+ self.setMargin( 1 + frameW)
+ self.setFrameStyle(QtGui.QFrame.NoFrame)
+ self.setAlignment(QtCore.Qt.AlignLeft)
+ self.setIndent(1)
+
+ self.installEventFilter(self)
+
+ opacity = self.style().styleHint(
+ QtGui.QStyle.SH_ToolTipLabel_Opacity,
+ None,
+ self
+ )
+ self.setWindowOpacity( opacity / 255.0)
+ self.setPalette(QtGui.QToolTip.palette())
+
+
+
+ def showDelay(self):
+ """returns the current show delay"""
+ return self._showDelay
+
+ def setShowDelay(self, n):
+ """adjusts the show delay
+ @param n milliseconds to delay the popup of the tooltip
+ """
+ self._showDelay = n
+
+
+ def paintEvent(self, event):
+ """overwritten QWidget.paintEvent"""
+ p = QtGui.QStylePainter(self)
+
+ opt = QtGui.QStyleOptionFrame()
+ opt.init(self)
+ p.drawPrimitive(QtGui.QStyle.PE_PanelTipLabel, opt)
+ p.end()
+
+ QtGui.QLabel.paintEvent(self, event)
+
+
+
+ def eventFilter(self, obj, event):
+ """event filter for the tooltip"""
+
+ type_ = event.type()
+ if type_ == event.KeyPress or type == event.KeyRelease:
+ key = event.key()
+ modifiers = event.modifiers()
+ if modifiers & QtCore.Qt.KeyboardModifierMask or \
+ key == QtCore.Qt.Key_Shift or \
+ key == QtCore.Qt.Key_Control or \
+ key == QtCore.Qt.Key_Alt or \
+ key == QtCore.Qt.Key_Meta:
+ return False
+
+ # TODO: delegate mouseactions to the window underneath the cursor
+ elif type_ in (
+ event.Leave,
+ event.WindowActivate,
+ event.WindowDeactivate,
+ event.MouseButtonPress,
+ event.MouseButtonRelease,
+ event.MouseButtonDblClick,
+ event.FocusIn,
+ event.FocusOut,
+ event.Wheel,
+ ):
+ self.hideTip()
+
+ return False
+
+
+ def onShowTip(self):
+ """called when the tooltip is about to be displayed"""
+
+ if self._currentAreaTipData:
+ pt, text, rc = self._currentAreaTipData
+ pos = QtGui.QCursor().pos()
+ if not rc.contains(pos):
+ return
+
+ desktop = QtGui.QApplication.desktop()
+ if desktop.isVirtualDesktop():
+ scr = desktop.screenNumber(pt)
+ else:
+ scr = desktop.screenNumber(self.parent())
+
+ if os.name == "mac":
+ screen = desktop.availableGeometry(scr)
+ else:
+ screen = desktop.screenGeometry(scr)
+
+ self.setText(text)
+ fm = QtGui.QFontMetrics(self.font())
+ extra = QtCore.QSize(1, 0)
+ # Make it look good with the default ToolTip font on Mac,
+ # which has a small descent.
+ if fm.descent() == 2 and fm.ascent() >= 11:
+ extra.setHeight(extra.height() + 1)
+
+ self.resize(self.sizeHint() + extra)
+
+ self.setWordWrap(QtCore.Qt.mightBeRichText(text))
+ self.move(pt)
+ self.show()
+
+
+ def cancel(self):
+ if self._showTimer.isActive():
+ self._showTimer.stop()
+
+
+ def hideTip(self):
+ """hides the tooltip"""
+ self.cancel()
+ self.hide()
+
+
+ def showText(self, pt, text, rc):
+ """shows the tooltip
+
+ @param pt: (global coordinates) point to show the tooltip at (left/top)
+ @param text: text to show (if emtpty string the tooltip is not shown)
+ @param rc: (global coordinates) bounding rect the tooltip is assigned to
+
+ """
+ self._currentAreaTipData = (pt, text, rc)
+ self.hideTip()
+ if not text.isEmpty():
+ self._showTimer.start(self._showDelay)
+
+
+ def showItemTip(self, itemView, index):
+ """Shows an item tip for item views (QTreeView, QListView ....)
+ for the specified index if necessary.
+
+ @param itemView: item view to display the tip for
+ @param index: QModelIndex of the item to display the tip for
+
+ Note: the tolltip will only be displayed if the text of the item is truncated
+ or the item is not entirely visible.
+ """
+ rc = self.getTruncatedItemRect(itemView, index)
+ if rc is not None:
+ text = index.data().toString()
+ if not text.isEmpty() and itemView.hasFocus():
+ self.showText(rc.topLeft(), text, rc)
+
+
+ def getTruncatedItemRect(self, itemView, index):
+ """Helper method. Returns the rect of a truncted item in an item view
+ @param itemView: QAbstractItemView
+ @param index: index of the item
+ @return: (global coordinates QRect) if the item is truncated, None otherwise
+ @note: this method is callled by showItemTip() to determine wether to
+ display a toolTip for an item or not. Overwrite to customize
+ """
+ viewport = itemView.viewport()
+ rcCli = viewport.contentsRect()
+ rcActual = itemView.visualRect(index)
+ rcDesired = QtCore.QRect(
+ rcActual.topLeft(),
+ itemView.sizeHintForIndex(index)
+ )
+ if not rcActual.contains(rcDesired, False) or \
+ not rcCli.contains(rcDesired, False):
+
+ rcActual.moveTo( viewport.mapToGlobal(rcActual.topLeft()) )
+ return rcActual
+
+
+#****************************************************************************
+#
+#****************************************************************************
+class ItemTips(QtCore.QObject):
+ """Equips an itemView (QTreeView, QListView ....) with tooltips for truncated items (item tips)
+ """
+
+ def __init__(self, itemView, showDelay=DEFAULT_SHOW_DELAY):
+ """
+ @param itemView: itemView to equip with item tips
+ param showDelay: delay in (miliseconds) after wich to show a tooltip for an item
+ """
+ QtCore.QObject.__init__(self, itemView)
+
+ self.areaTip = AreaTip(itemView, showDelay=showDelay)
+ self.itemView = itemView
+
+ itemView.setMouseTracking(True) # enshure we get mouseMove messages
+ itemView.viewport().installEventFilter(self)
+
+
+ def eventFilter(self, obj, event):
+ """Event filter for the itemTip"""
+ if event.type() == event.MouseMove:
+ if self.areaTip.isHidden():
+
+ # hope this check fixes a glitch with comboBoxes. Sometimes am itemTip
+ # did pop up when the combos dropdown was closed.
+ if not self.itemView.isHidden() and self.itemView.isEnabled() and self.itemView.underMouse():
+ index = self.itemView.indexAt(event.pos())
+ if index.isValid():
+ self.areaTip.showItemTip(self.itemView, index)
+ if event.type() == event.Leave:
+ self.areaTip.cancel()
+
+ return False
+
+
+ def setEnabled(self, flag):
+ self.areaTip.setEnabled(flag)
+ pass
+
+ def isEnabled(self):
+ self.areaTip.isEnabled()
+
+ def getShowDelay(self):
+ """returns the current show delay"""
+ return self.areaTip.getShowDelay()
+
+ def setShowDelay(self, n):
+ """adjusts the show delay
+ @param n milliseconds to delay the popup of the tooltip
+ """
+ return self.areaTip.setShowDelay(delay)
+
+#****************************************************************************
+#
+#****************************************************************************
+class ComboBoxEditTips(QtCore.QObject):
+ """Equips a QComboBox with a toolTip popping up when the text in its edit box is truncated
+
+ @note: this class does currently not quite what it is supposed todo. A normal toolTip is
+ sisplayed instead of a toolTip that covers the editBox. This may change in future versions.
+ """
+
+ def __init__(self, comboBox, showDelay=DEFAULT_SHOW_DELAY):
+ QtCore.QObject.__init__(self, comboBox)
+
+ self.connect(
+ comboBox,
+ QtCore.SIGNAL('currentIndexChanged(const QString &)'),
+ self._adjustToolTip
+ )
+
+ comboBox.installEventFilter(self)
+ self.comboBox = comboBox
+
+
+ def eventFilter(self, obj, event):
+ if event.type() == event.Resize:
+ self._adjustToolTip(self.comboBox.currentText())
+ return False
+
+ def _adjustToolTip(self, text):
+ fm = self.comboBox.fontMetrics()
+ style = self.comboBox.style()
+ rc = self.comboBox.contentsRect()
+ rc2 = style.subControlRect(
+ style.CC_ComboBox,
+ QtGui.QStyleOptionComboBox(),
+ style.SC_ComboBoxEditField,
+ )
+
+ cx = rc.width() + rc2.width()
+ w = fm.width(text)
+ if w > cx -2:
+ self.comboBox.setToolTip(text)
+ else:
+ self.comboBox.setToolTip('')
+
+
+
+
+#********************************************************************************************
+# some test guis
+#********************************************************************************************
+def _testItemModel():
+ """Tests itemTips for a QTableView"""
+
+ import sys
+
+
+ class TestModel(QtCore.QAbstractTableModel):
+
+
+ def __init__(self, table):
+ QtCore.QAbstractTableModel.__init__(self, table)
+
+ self.__table = table
+ self.__columns = ('foo', "foo")
+ self.__rows = ['foo'*10 for i in range(10)]
+
+ self.areaTip = AreaTip(table)
+
+
+ def hasIndex(self, row, column):
+ """QAbstractTableModel.hasIndex() implementation"""
+ if -1 < column <= len(self.__columns):
+ if -1 < row < len(self.__rows):
+ return True
+ return False
+
+ def rowCount(self, parent):
+ """QAbstractTableModel.rowCount() implementation"""
+ return len(self.__rows)
+
+
+ def columnCount(self, parent):
+ """QAbstractTableModel.columnCount() implementation"""
+ return len(self.__columns)
+
+
+ def headerData(self, section, orientation, role):
+ """QAbstractTableModel.headerData() implementation"""
+ if role == QtCore.Qt.DisplayRole and orientation == QtCore.Qt.Horizontal:
+ return QtCore.QVariant(self.__columns[section])
+ return QtCore.QVariant()
+
+
+ def data(self, index, role):
+ """QAbstractTableModel.data() implementation"""
+
+ if self.hasIndex(index.row(), index.column()):
+ if role == QtCore.Qt.DisplayRole:
+ return QtCore.QVariant(self.__rows[index.column()])
+
+ # display tooltip if text does not fit column width
+ # or item is not entirely visible
+ elif role == QtCore.Qt.ToolTipRole:
+ self.areaTip.showItemTip(self.__table, index)
+
+
+ return QtCore.QVariant()
+
+ app = QtGui.QApplication(sys.argv)
+ dlg = QtGui.QWidget()
+
+ grid = QtGui.QHBoxLayout(dlg)
+
+ tv = QtGui.QTableView(dlg)
+ grid.addWidget(tv)
+
+ tv.setModel(TestModel(tv))
+
+ dlg.show()
+ res = app.exec_()
+ sys.exit(res)
+
+
+
+def _testComboBox():
+ """Tests itemTips for a QCombobox"""
+
+
+ import sys
+
+ app = QtGui.QApplication(sys.argv)
+ w = QtGui.QWidget()
+
+ b = QtGui.QGridLayout(w)
+ c = QtGui.QComboBox(w)
+ c.setMinimumContentsLength(5)
+ b.addWidget(c)
+
+ itemTips = ItemTips(c.view())
+
+
+ for i in range(10):
+ c.addItem('loooooooooooooooooooooooooooooong-itemText-%s' % i)
+
+ w.show()
+ res = app.exec_()
+ sys.exit(res)
+
+
+
+#***********************************************************************
+#
+#***********************************************************************
+if __name__ == "__main__":
+ pass
+ _testItemModel()
+ #_testComboBox()
+
+
+
Added: trunk/fclient/src/fclient/lib/qt4ex/checkarraywrap.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/checkarraywrap.py (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/checkarraywrap.py 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,93 @@
+"""wrapper class for handling checkboxes (...) as bit array
+
+
+CONST_1 = 1
+CONST_2 = 2
+CONST_3 = 4
+
+checks = {
+ CONST_1: ckeckbox1,
+ CONST_2: checkbox2,
+ CONST_3: cjeckbox3,
+
+ }
+
+
+flags = CheckArray(checks, initvalue=CONST_1 | CONST_2)
+
+flags |= CONST_3 # check 3rd checkbox
+flags.showChecks(CONST_1 | CONST_2) # hide 3rd checkbox
+
+"""
+
+from PyQt4 import QtCore
+#*******************************************************
+#
+#*******************************************************
+class CheckArrayWrap(QtCore.QObject):
+
+ def __init__(self, parent, checks, value=None):
+ QtCore.QObject.__init__(self, parent)
+ self._checks = checks
+
+ if value is not None:
+ self.setChecks(value)
+
+ ######################################
+ ## public methods
+ ######################################
+ def getValue(self):
+ value = 0
+ for const, ck in self._checks.items():
+ if ck.isChecked():
+ value |= const
+ return value
+
+
+ def setChecks(self, flags):
+ for const, ck in self._checks.items():
+ if flags & const:
+ ck.setCheckState(QtCore.Qt.Checked)
+ else:
+ ck.setCheckState(QtCore.Qt.Unchecked)
+ flags &= ~const
+ if not flags:
+ break
+
+
+ def showChecks(self, flags):
+ for const, ck in self._checks.items():
+ if flags & const:
+ check.control.setEnabled(True)
+ check.control.show()
+ else:
+ check.control.setEnabled(False)
+ check.control.hide()
+ flags &= ~const
+ if not flags:
+ break
+
+
+ def __or__(self, n):
+ value = self.getValue() | n
+ self.setChecks(value)
+ return self
+ def __ior__(self, n): return self.__or__(n)
+ def __ror__(self, n): return self.__or__(n)
+
+ def __and__(self, n):
+ value = self.getValue() & n
+ self.setChecks(value)
+ return self
+ def __iand__(self, n): return self.__and__(n)
+ def __rand__(self, n): return self.__and__(n)
+
+ def __xor__(self, n):
+ value = self.getValue() ^ n
+ self.setChecks(value)
+ return self
+ def __ixor__(self, n): return self.__xor__(n)
+ def __rxor__(self, n): return self.__xor__(n)
+
+
+
Added: trunk/fclient/src/fclient/lib/qt4ex/colorbutton.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/colorbutton.py (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/colorbutton.py 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,228 @@
+"""pyQt4 ColorButton with drag and drop support
+
+mostly taken from
+[http://api.kde.org/4.0-api/kdelibs-apidocs/kdeui/html/classKColorButton.html]
+with some minor adjustements
+"""
+from __future__ import absolute_import
+if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
+ import os; __path__ = [os.path.dirname(__file__)]
+
+
+import sys, os
+from PyQt4 import QtCore, QtGui
+
+from .lib import tools
+#************************************************************************
+#
+#************************************************************************
+class ColorButtonWrap(QtCore.QObject):
+ """Event filter to transform a QPushButton into a color button
+
+ The button will popup a color selection dialog when hit ++ the button supports
+ drag / drop of colors.
+
+ @signal colorChanged(const QColor*): emited when the user changes the color of
+ the button via color dialog or color drop.
+ """
+
+ def __init__(self, button, color=None, fitColor=True):
+ """
+ @param button: button to wrap
+ @param color: initial color. If None, initial color is black
+ @fitColor: if True the color shown is adjusted to fit the contents of the button
+ """
+ QtCore.QObject.__init__(self, button)
+
+ self.button = button
+ self._color = color or QtGui.QColor('black')
+ self.fitColor = fitColor
+
+ button.setAcceptDrops(True)
+ button.installEventFilter(self)
+ self.connect(button, QtCore.SIGNAL('clicked()'), self.chooseColor)
+
+
+ def _initStyleOption(self, opt):
+ opt.initFrom(self.button)
+ opt.text.clear()
+ opt.icon = QtGui.QIcon()
+ opt.features = QtGui.QStyleOptionButton.None
+
+
+ def eventFilter(self, obj, event):
+ """Event filter for the button wrapped"""
+
+ eventType = event.type()
+
+ if eventType == event.Paint:
+ painter = QtGui.QPainter(self.button)
+
+ # draw bevel
+ opt = QtGui.QStyleOptionButton()
+ self._initStyleOption(opt)
+ self.button.style().drawControl(QtGui.QStyle.CE_PushButtonBevel, opt, painter, self.button)
+
+ # draw color box
+ #First, sort out where it goes
+ labelRect = self.button.style().subElementRect(QtGui.QStyle.SE_PushButtonContents, opt, self.button)
+ shift = self.button.style().pixelMetric(QtGui.QStyle.PM_ButtonMargin)
+ labelRect.adjust(shift, shift, -shift, -shift);
+ x, y, w, h = labelRect.getRect()
+
+ if self.button.isChecked() or self.button.isDown():
+ x += self.button.style().pixelMetric(QtGui.QStyle.PM_ButtonShiftHorizontal)
+ y += self.button.style().pixelMetric(QtGui.QStyle.PM_ButtonShiftVertical)
+ if self.button.isEnabled():
+ fillCol = self.getColor()
+ else:
+ fillCol = self.button.palette().color(self.button.backgroundRole())
+
+ QtGui.qDrawShadePanel(painter, x, y, w, h, self.button.palette(), True, 1, None)
+ if fillCol.isValid():
+ painter.fillRect( x+1, y+1, w-2, h-2, fillCol)
+
+ if self.button.hasFocus():
+ focusRect = self.button.style().subElementRect(QtGui.QStyle.SE_PushButtonFocusRect, opt, self.button)
+ focusOpt = QtGui.QStyleOptionFocusRect()
+ focusOpt.initFrom(self.button)
+ focusOpt.rect = focusRect
+ focusOpt.backgroundColor = self.button.palette().background().color()
+ self.button.style().drawPrimitive(QtGui.QStyle.PE_FrameFocusRect, focusOpt, painter, self.button)
+ return True
+
+ elif eventType == event.MouseMove:
+ if not self._mouse_pressed:
+ return False
+
+ if event.buttons() & QtCore.Qt.LeftButton:
+ if (self._mousepress_pos - event.pos()).manhattanLength() > QtGui.QApplication.startDragDistance():
+ self._mouse_pressed = False
+ self.button.setDown(False)
+ drag = QtGui.QDrag(self.button)
+ data = QtCore.QMimeData()
+ data.setColorData(QtCore.QVariant(self._color))
+ drag.setMimeData(data)
+ drag.start(QtCore.Qt.CopyAction)
+ return True
+
+ elif eventType == event.MouseButtonPress:
+ self._mousepress_pos = QtCore.QPoint(event.pos())
+ self._mouse_pressed = True
+ return False
+
+ elif eventType == event.MouseButtonRelease:
+ self._mouse_pressed = False
+ return False
+
+ elif eventType == event.DragEnter:
+ if event.mimeData().hasColor():
+ event.accept()
+ else:
+ event.ignore()
+ return True
+
+ elif eventType == event.DragMove:
+ if event.mimeData().hasColor():
+ event.accept()
+ else:
+ Event.ignore()
+ return True
+
+ elif eventType == event.Drop:
+ if event.mimeData().hasColor():
+ v = event.mimeData().colorData()
+ self.setColor( QtGui.QColor(v.toString() ) )
+ else:
+ event.ignore()
+ return True
+
+
+ # TODO: copy & paste
+ if eventType == event.KeyPress:
+
+ if Qt4ExTools.isStandardKeyEvent(event, QtGui.QKeySequence.Copy):
+ mimeData = QtCore.QMimeData()
+ mimeData.setColorData(QtCore.QVariant(self.getColor() ) )
+ QtGui.QApplication.clipboard().setMimeData(mimeData, QtGui.QClipboard.Clipboard)
+ elif qtools.isStandardKeyEvent(event, QtGui.QKeySequence.Paste):
+ mimeData = QtGui.QApplication.clipboard().mimeData(QtGui.QClipboard.Clipboard)
+ if mimeData.hasColor():
+ v = mimeData.colorData()
+ self.setColor( QtGui.QColor(v.toString() ) )
+
+
+
+
+
+ """
+ void KColorButton::keyPressEvent( QKeyEvent *e )
+ {
+ int key = e->key() | e->modifiers();
+
+ if ( KStandardShortcut::copy().contains( key ) ) {
+ QMimeData *mime=new QMimeData;
+ KColorMimeData::populateMimeData(mime,color());
+ QApplication::clipboard()->setMimeData( mime, QClipboard::Clipboard );
+ }
+ else if ( KStandardShortcut::paste().contains( key ) ) {
+ QColor color=KColorMimeData::fromMimeData( QApplication::clipboard()->mimeData( QClipboard::Clipboard ));
+ setColor( color );
+ }
+ else
+ QPushButton::keyPressEvent( e );
+ }
+ """
+
+ return False
+
+
+ #############################################
+ ## methods
+ #############################################
+ def chooseColor(self):
+ """Pops up a color selection dialog to adjust the color of the button"""
+ color = QtGui.QColorDialog.getColor(self._color, self.button)
+ if color.isValid():
+ self.setColor(color)
+ self.emit(QtCore.SIGNAL('colorChanged(const QColor*)'), color)
+
+ def getColor(self):
+ """Returns the color of the button
+ @return: QColor
+ """
+ return self._color
+
+ def setColor(self, color):
+ """Sets the color of the button
+ @param color: QColor
+ """
+ self._color = color
+ self.button.update()
+ self.emit(QtCore.SIGNAL('colorChanged(const QColor*)'), color)
+
+
+#********************************************************************
+#
+#********************************************************************
+if __name__ == '__main__':
+ import sys
+
+ app = QtGui.QApplication(sys.argv)
+ w = QtGui.QWidget(None)
+ box = QtGui.QVBoxLayout(w)
+ colors = ('yellow', 'red', 'green', 'blue')
+ for color in colors:
+ bt = QtGui.QPushButton(w)
+ wrap = ColorButtonWrap(bt, QtGui.QColor(color))
+ box.addWidget(bt)
+
+
+
+ w.show()
+ res = app.exec_()
+ sys.exit(res)
+
+
+
+
\ No newline at end of file
Added: trunk/fclient/src/fclient/lib/qt4ex/dlgabout.py
===================================================================
--- trunk/fclient/src/fclient/lib/qt4ex/dlgabout.py (rev 0)
+++ trunk/fclient/src/fclient/lib/qt4ex/dlgabout.py 2008-07-13 09:43:02 UTC (rev 604)
@@ -0,0 +1,123 @@
+from __future__ import absolute_import
+if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
+ import os; __path__ = [os.path.dirname(__file__)]
+
+import sys, os
+import cPickle
+from PyQt4 import QtCore, QtGui
+
+from .tpls.Ui_DlgAbout import Ui_DlgAbout
+from .lib import tools
+#*********************************************************************
+#
+#*********************************************************************
+class DlgAbout(QtGui.QDialog, Ui_DlgAbout):
+
+ # control ids
+ IdLabelAbout = 'label_about'
+
+
+ def __init__(self,
+ parent,
+ state=None,
+ caption=None,
+ appName=None,
+ description=None,
+ version=None,
+ author=None,
+ email=None,
+ licence=None,
+ copyright=None,
+ ):
+ """
+ @param state: formerly saved state of the dialog or None
+ @param caption: ttle of the dialog or None
+ @note: all other keyword params should be pretty self explanatory and
+ should be (str, QString).
+
+ """
+
+ QtGui.QDialog.__init__(self, parent)
+ self.setupUi(self)
+
+ if caption is not None:
+ self.setWindowTitle(caption)
+
+ label = self.controlById(self.IdLabelAbout)
+
+ text = ''
+ if appName is not None:
+ text += '<h3>%s</h3>\n' % appName
+ if description is not None:
+ text += '<hr>%s<hr>\n' % description
+
+ text += '<ul>\n'
+ if version is not None:
+ text += ' <li>Version: %s\n' % version
+ if author is not None:
+ text += ' <li>Author: %s\n' % author
+ if email is not None:
+ text += ' <li>Email: %s\n' % email
+ if licence is not None:
+ text += ' <li>Licence: %s\n' % licence
+ if copyright is not None:
+ text += ' <li>Copyright...
[truncated message content] |