[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kexi
From: Jarosław Staniek <staniek () kde ! org>
Date: 2009-11-04 16:21:12
Message-ID: 1257351672.535756.9757.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1044783 by staniek:
Forms
*image box widget:
**displaying images ported to Qt 4
**display frame for frameless boxes in design mode (like for the label)
**fix missing icons for the context menu
M +36 -46 kexiutils/utils.cpp
M +56 -27 plugins/forms/widgets/kexidbimagebox.cpp
M +2 -2 widget/utils/kexicontextmenuutils.cpp
--- trunk/koffice/kexi/kexiutils/utils.cpp #1044782:1044783
@@ -389,29 +389,13 @@
void KexiUtils::drawPixmap(QPainter& p, const WidgetMargins& margins, const QRect& \
rect,
const QPixmap& pixmap, Qt::Alignment alignment, bool \
scaledContents, bool keepAspectRatio) {
-#ifdef __GNUC__
-#warning TODO KexiUtils::drawPixmap
-#else
-#pragma WARNING(TODO KexiUtils::drawPixmap)
-#endif
- // The code below is excluded from compilation, this generates lots of warnings
- // with GCC since no arguments get used
- // Temporary fix follows.
- Q_UNUSED(p);
- Q_UNUSED(margins);
- Q_UNUSED(rect);
- Q_UNUSED(pixmap);
- Q_UNUSED(alignment);
- Q_UNUSED(scaledContents);
- Q_UNUSED(keepAspectRatio);
-#if 0 //todo
if (pixmap.isNull())
return;
- const bool fast = pixmap.width() > 1000 && pixmap.height() > 800; //fast drawing \
needed
- const int w = rect.width() - lineWidth - lineWidth;
- const int h = rect.height() - lineWidth - lineWidth;
-//! @todo we can optimize drawing by drawing rescaled pixmap here
+ const bool fast = false;//pixmap.width() > 1000 && pixmap.height() > 800; //fast \
drawing needed + const int w = rect.width() - margins.left - margins.right;
+ const int h = rect.height() - margins.top - margins.bottom;
+//! @todo we can optimize painting by drawing rescaled pixmap here
//! and performing detailed painting later (using QTimer)
QPixmap pixmapBuffer;
QPainter p2;
@@ -429,39 +413,47 @@
QPoint pos;
if (scaledContents) {
if (keepAspectRatio) {
- QImage img(pixmap.convertToImage());
- img = img.smoothScale(w, h, QImage::ScaleMin);
- pos = rect.topLeft(); //0, 0);
+ QImage img(pixmap.toImage());
+ img = img.scaled(w, h, Qt::KeepAspectRatio);
+ pos = rect.topLeft();
if (img.width() < w) {
- int hAlign = QApplication::horizontalAlignment(alignment);
- if (hAlign & Qt::AlignRight)
+// int hAlign = QApplication::horizontalAlignment(alignment);
+ if (alignment & Qt::AlignRight)
pos.setX(pos.x() + w - img.width());
- else if (hAlign & Qt::AlignHCenter)
+ else if (alignment & Qt::AlignHCenter)
pos.setX(pos.x() + w / 2 - img.width() / 2);
- } else if (img.height() < h) {
+ }
+ else if (img.height() < h) {
if (alignment & Qt::AlignBottom)
pos.setY(pos.y() + h - img.height());
else if (alignment & Qt::AlignVCenter)
pos.setY(pos.y() + h / 2 - img.height() / 2);
}
- pixmapBuffer.convertFromImage(img);
+ pixmapBuffer.fromImage(img);
if (!fast) {
- p2.begin(&pixmapBuffer, p.device());
- } else
+ p2.begin(&pixmapBuffer);
+// p2.initFrom(p.device());
+ }
+ else {
target->drawPixmap(pos, pixmapBuffer);
+ }
} else {
if (!fast) {
- pixmapBuffer.resize(rect.size() - QSize(lineWidth, lineWidth));
- p2.begin(&pixmapBuffer, p.device());
+ pixmapBuffer = QPixmap(rect.size() - QSize(margins.right, \
margins.bottom)); + p2.begin(&pixmapBuffer);
+ //, p.device());
p2.drawPixmap(QRect(rect.x(), rect.y(), w, h), pixmap);
- } else
- target->drawPixmap(QRect(rect.x() + lineWidth, rect.y() + lineWidth, \
w, h), pixmap); + }
+ else {
+ target->drawPixmap(QRect(rect.x() + margins.left, rect.y() + \
margins.top, w, h), pixmap); + }
}
- } else {
- int hAlign = QApplication::horizontalAlignment(alignment);
- if (hAlign & Qt::AlignRight)
+ }
+ else {
+// int hAlign = QApplication::horizontalAlignment(alignment);
+ if (alignment & Qt::AlignRight)
pos.setX(pos.x() + w - pixmap.width());
- else if (hAlign & Qt::AlignHCenter)
+ else if (alignment & Qt::AlignHCenter)
pos.setX(pos.x() + w / 2 - pixmap.width() / 2);
else //left, etc.
pos.setX(pos.x());
@@ -475,18 +467,16 @@
// target->drawPixmap(pos, pixmap);
// if (!fast)
// p2.begin(&pixmapBuffer, p.device());
- p.drawPixmap(lineWidth + pos.x(), lineWidth + pos.y(), pixmap);
+ p.drawPixmap(margins.left + pos.x(), margins.top + pos.y(), pixmap);
}
if (scaledContents && !fast && p.isActive()) {
p2.end();
- bitBlt(p.device(),
-// pos.x(),
-// pos.y(),
- (int)p.worldMatrix().dx() + rect.x() + lineWidth + pos.x(),
- (int)p.worldMatrix().dy() + rect.y() + lineWidth + pos.y(),
- &pixmapBuffer);
+ p.drawPixmap(
+ (int)p.worldMatrix().dx() + rect.x() + margins.left + pos.x(),
+ (int)p.worldMatrix().dy() + rect.y() + margins.top + pos.y(),
+ pixmapBuffer,
+ rect.x(), rect.y(), w, h);
}
-#endif
}
QString KexiUtils::ptrToStringInternal(void* ptr, uint size)
--- trunk/koffice/kexi/plugins/forms/widgets/kexidbimagebox.cpp #1044782:1044783
@@ -50,6 +50,7 @@
#include <kexidb/utils.h>
#include <kexidb/queryschema.h>
#include <formeditor/widgetlibrary.h>
+#include <formeditor/utils.h>
#include <kexi_global.h>
//#ifdef Q_WS_WIN
@@ -89,6 +90,9 @@
setDesignMode(designMode);
installEventFilter(this);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ QPalette pal(palette());
+ pal.setBrush(backgroundRole(), QBrush(Qt::transparent));
+ KexiFrame::setPalette(pal);
//setup context menu
m_contextMenu = new KexiImageContextMenu(this);
@@ -633,6 +637,24 @@
}
}
+static QPixmap *scaledImageBoxIcon(const KexiUtils::WidgetMargins& margins, const \
QSize& size) +{
+ const int realHeight = size.height() - margins.top - margins.bottom;
+ const int realWidth = size.width() - margins.left - margins.right;
+ const bool tooLarge = (size.height() - margins.top - margins.bottom) <= \
KexiDBImageBox_static->pixmap->height(); + if ( realHeight <= \
KexiDBImageBox_static->pixmap->height() + || realWidth <= \
KexiDBImageBox_static->pixmap->width()) + {
+ if ( realHeight <= KexiDBImageBox_static->small->height()
+ || realWidth <= KexiDBImageBox_static->small->width())
+ {
+ return 0;
+ }
+ return KexiDBImageBox_static->small;
+ }
+ return KexiDBImageBox_static->pixmap;
+}
+
void KexiDBImageBox::paintEvent(QPaintEvent *pe)
{
if (!m_paintEventEnabled)
@@ -643,25 +665,24 @@
KexiUtils::WidgetMargins margins(this);
margins += KexiUtils::WidgetMargins(_realLineWidth);
//Qt3 replaced with 'margins': const int m = realLineWidth() + margin();
- QColor bg(palette().color(backgroundRole())); //Qt3 eraseColor());
+ const QBrush bgBrush(palette().brush(backgroundRole()));
if (designMode() && pixmap().isNull()) {
- QRect r(QPoint(margins.left, margins.top), size() - QSize(margins.left + \
margins.right, margins.top + margins.bottom));
- p.fillRect(0, 0, width(), height(), bg);
+ QRect r(
+ QPoint(margins.left, margins.top),
+ size() - QSize(margins.left + margins.right, margins.top + \
margins.bottom)); +// p.fillRect(0, 0, width(), height(), bgBrush);
updatePixmap();
- QPixmap *imagBoxPm;
- const bool tooLarge = (height() - margins.top - margins.bottom) <= \
KexiDBImageBox_static->pixmap->height();
- if (tooLarge || (width() - margins.left - margins.right) <= \
KexiDBImageBox_static->pixmap->width())
- imagBoxPm = KexiDBImageBox_static->small;
- else
- imagBoxPm = KexiDBImageBox_static->pixmap;
- QImage img(imagBoxPm->toImage());
-
- QPixmap converted(QPixmap::fromImage(img));
- p.drawPixmap(2, height() - margins.top - margins.bottom - \
imagBoxPm->height() - 2, converted); + QPixmap *imagBoxPm = \
scaledImageBoxIcon(margins, size()); + if (imagBoxPm) {
+// QImage img(imagBoxPm->toImage());
+// QPixmap converted(QPixmap::fromImage(img));
+ p.drawPixmap(2, height() - margins.top - margins.bottom - \
imagBoxPm->height() - 2, *imagBoxPm); + }
QFont f(qApp->font());
p.setFont(f);
- p.setPen(KexiUtils::contrastColor(bg));
+// p.setPen(KexiUtils::contrastColor(bg));
+ p.setPen(palette().brush(QPalette::WindowText));
p.drawText(r, Qt::AlignCenter,
dataSource().isEmpty()
? objectName() + "\n" + i18nc("Unbound Image Box", "(unbound)")
@@ -673,26 +694,33 @@
internalSize.setWidth(internalSize.width() - m_chooser->width());
//clearing needed here because we may need to draw a pixmap with \
transparency
- p.fillRect(0, 0, width(), height(), bg);
+ // p.fillRect(0, 0, width(), height(), bgBrush);
KexiUtils::drawPixmap(p, margins, QRect(QPoint(0, 0), internalSize), \
pixmap(), m_alignment, m_scaledContents, m_keepAspectRatio);
}
KexiFrame::drawFrame(&p);
- // if the widget is focused, draw focus indicator rect _if_ there is no chooser \
button
- if ( !designMode()
- && !dataSource().isEmpty()
- && hasFocus()
- && (!m_chooser || !m_chooser->isVisible()))
- {
- QStyleOptionFocusRect option;
- option.initFrom(this);
- //option.rect = style().subRect(QStyle::SR_PushButtonContents);
- style()->drawPrimitive(
- QStyle::PE_FrameFocusRect, &option, &p, this
- /*Qt4 , palette().active()*/);
+ if (designMode()) {
+ const bool hasFrame = frameWidth() >= 1 && frameShape() != QFrame::NoFrame;
+ if (!hasFrame) {
+ KFormDesigner::paintWidgetFrame(p, rect());
+ }
}
+ else { // data mode
+ // if the widget is focused, draw focus indicator rect _if_ there is no \
chooser button + if ( !dataSource().isEmpty()
+ && hasFocus()
+ && (!m_chooser || !m_chooser->isVisible()))
+ {
+ QStyleOptionFocusRect option;
+ option.initFrom(this);
+ //option.rect = style().subRect(QStyle::SR_PushButtonContents);
+ style()->drawPrimitive(
+ QStyle::PE_FrameFocusRect, &option, &p, this
+ /*Qt4 , palette().active()*/);
+ }
+ }
}
/* virtual void KexiDBImageBox::paletteChange ( const QPalette & oldPalette )
@@ -716,6 +744,7 @@
"image-x-generic", KIconLoader::NoGroup, KIconLoader::SizeLarge, \
KIconLoader::DisabledState) ); if (!pm.isNull()) {
KIconEffect::semiTransparent(pm);
+ KIconEffect::semiTransparent(pm);
}
KexiDBImageBox_static->pixmap = new QPixmap(pm);
KexiDBImageBox_static->small = new QPixmap(
--- trunk/koffice/kexi/widget/utils/kexicontextmenuutils.cpp #1044782:1044783
@@ -70,7 +70,7 @@
d->actionCollection.addAction("insert",
d->insertFromFileAction = new KAction(
- KIcon("fileopen"), i18n("Insert From &File..."), this));
+ KIcon("document-open"), i18n("Insert From &File..."), this));
connect(d->insertFromFileAction, SIGNAL(triggered()),
this, SLOT(insertFromFile()));
addAction(d->insertFromFileAction);
@@ -86,7 +86,7 @@
addAction(d->pasteAction);
d->actionCollection.addAction("delete",
d->deleteAction = new KAction(
- KIcon("editdelete"), i18n("&Clear"), this));
+ KIcon("edit-clear"), i18n("&Clear"), this));
connect(d->deleteAction, SIGNAL(triggered()),
this, SLOT(clear()));
addAction(d->deleteAction);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic