From 5c42c523d92e5f476c51b88870cdfe9f33d6c39b Mon Sep 17 00:00:00 2001 From: jpbl <jpbl> Date: Thu, 13 Oct 2005 17:59:19 +0000 Subject: [PATCH] We have transparency for qt3 --- src/gui/official/JPushButton.cpp | 22 +++--------- src/gui/official/RequesterImpl.cpp | 2 +- src/gui/official/SFLLcd.cpp | 10 +++--- src/gui/official/SFLPhoneWindow.cpp | 43 +++++++++++----------- src/gui/official/TCPSessionIO.cpp | 2 +- src/gui/official/TransparentWidget.cpp | 50 +++++++++++++++++++++----- src/gui/official/TransparentWidget.hpp | 8 +++++ src/gui/official/VolumeControl.cpp | 8 +++-- src/gui/official/globals.h | 6 ---- src/gui/official/sflphone.pro | 1 + 10 files changed, 89 insertions(+), 63 deletions(-) diff --git a/src/gui/official/JPushButton.cpp b/src/gui/official/JPushButton.cpp index 505f7d4925..64a389e7b4 100644 --- a/src/gui/official/JPushButton.cpp +++ b/src/gui/official/JPushButton.cpp @@ -29,6 +29,7 @@ #include "globals.h" #include "JPushButton.hpp" +#include "TransparentWidget.hpp" JPushButton::JPushButton(const QString &released, const QString &pressed, @@ -54,28 +55,16 @@ JPushButton::setToggle(bool toggle) QPixmap JPushButton::transparize(const QString &image) { - /** - if (!p.mask()) { - if (p.hasAlphaChannel()) { - p.setMask(p.alphaChannel()); - } - else { - p.setMask(p.createHeuristicMask()); - } - } - */ - return QPixmap::fromMimeSource(image); + return TransparentWidget::transparize(image); } void JPushButton::release() { setPixmap(mImages[0]); - /* if(mImages[0].hasAlpha()) { - setMask(mImages[0].mask()); + setMask(*mImages[0].mask()); } - */ resize(mImages[0].size()); } @@ -83,10 +72,9 @@ void JPushButton::press() { setPixmap(mImages[1]); - /* if(mImages[1].hasAlpha()) { - setMask(mImages[1].mask()); - }*/ + setMask(*mImages[1].mask()); + } resize(mImages[1].size()); } diff --git a/src/gui/official/RequesterImpl.cpp b/src/gui/official/RequesterImpl.cpp index a98f2c4de7..2c5bfa4bc6 100644 --- a/src/gui/official/RequesterImpl.cpp +++ b/src/gui/official/RequesterImpl.cpp @@ -164,7 +164,7 @@ RequesterImpl::generateCallId() QString RequesterImpl::generateSessionId() { - return QString("cSessionID:").arg(mSequenceIdCount++); + return QString("cSessionID:%1").arg(mSequenceIdCount++); } QString diff --git a/src/gui/official/SFLLcd.cpp b/src/gui/official/SFLLcd.cpp index 065e56070b..39ac11f83e 100644 --- a/src/gui/official/SFLLcd.cpp +++ b/src/gui/official/SFLLcd.cpp @@ -5,18 +5,19 @@ #include "globals.h" #include "JPushButton.hpp" #include "SFLLcd.hpp" +#include "TransparentWidget.hpp" #define FONT_FAMILY "Courier" // Others fixed font support "Monospace", "Fixed", "MiscFixed" #define FONT_SIZE 10 -#define SCREEN "images/screen_main.png" -#define OVERSCREEN "images/overscreen.png" +#define SCREEN "screen_main.png" +#define OVERSCREEN "overscreen.png" SFLLcd::SFLLcd(QWidget *parent) : QLabel(parent) - , mScreen(JPushButton::transparize(SCREEN)) - , mOverscreen(JPushButton::transparize(OVERSCREEN)) + , mScreen(TransparentWidget::retreive(SCREEN)) + , mOverscreen(TransparentWidget::transparize(OVERSCREEN)) , mGlobalStatusPos(-1) , mLineStatusPos(-1) , mBufferStatusPos(-1) @@ -159,7 +160,6 @@ SFLLcd::paintEvent(QPaintEvent *) extractVisibleText(mBufferStatus, mBufferStatusPos)); p.drawText(QPoint(margin, mScreen.size().height() - margin), getTimeStatus()); - //p.drawPixmap(0,0, mScreen); p.drawPixmap(0,0, mOverscreen); p.end(); } diff --git a/src/gui/official/SFLPhoneWindow.cpp b/src/gui/official/SFLPhoneWindow.cpp index d6eec60b7e..49efd30cfc 100644 --- a/src/gui/official/SFLPhoneWindow.cpp +++ b/src/gui/official/SFLPhoneWindow.cpp @@ -20,23 +20,23 @@ #include "SFLLcd.hpp" #include "VolumeControl.hpp" -#define LOGO_IMAGE "images/logo_ico.png" -#define BACKGROUND_IMAGE "images/main.png" -#define HANGUP_RELEASED_IMAGE "images/hangup_off.png" -#define HANGUP_PRESSED_IMAGE "images/hangup_on.png" -#define HOLD_RELEASED_IMAGE "images/hold_off.png" -#define HOLD_PRESSED_IMAGE "images/hold_on.png" -#define OK_RELEASED_IMAGE "images/ok_off.png" -#define OK_PRESSED_IMAGE "images/ok_on.png" -#define CLEAR_RELEASED_IMAGE "images/clear_off.png" -#define CLEAR_PRESSED_IMAGE "images/clear_on.png" -#define MUTE_RELEASED_IMAGE "images/mute_off.png" -#define MUTE_PRESSED_IMAGE "images/mute_on.png" -#define VOLUME_IMAGE "images/volume.png" -#define CLOSE_RELEASED_IMAGE "images/close_off.png" -#define CLOSE_PRESSED_IMAGE "images/close_on.png" -#define MINIMIZE_RELEASED_IMAGE "images/minimize_off.png" -#define MINIMIZE_PRESSED_IMAGE "images/minimize_on.png" +#define LOGO_IMAGE "logo_ico.png" +#define BACKGROUND_IMAGE "main.png" +#define HANGUP_RELEASED_IMAGE "hangup_off.png" +#define HANGUP_PRESSED_IMAGE "hangup_on.png" +#define HOLD_RELEASED_IMAGE "hold_off.png" +#define HOLD_PRESSED_IMAGE "hold_on.png" +#define OK_RELEASED_IMAGE "ok_off.png" +#define OK_PRESSED_IMAGE "ok_on.png" +#define CLEAR_RELEASED_IMAGE "clear_off.png" +#define CLEAR_PRESSED_IMAGE "clear_on.png" +#define MUTE_RELEASED_IMAGE "mute_off.png" +#define MUTE_PRESSED_IMAGE "mute_on.png" +#define VOLUME_IMAGE "volume.png" +#define CLOSE_RELEASED_IMAGE "close_off.png" +#define CLOSE_PRESSED_IMAGE "close_on.png" +#define MINIMIZE_RELEASED_IMAGE "minimize_off.png" +#define MINIMIZE_PRESSED_IMAGE "minimize_on.png" @@ -54,12 +54,9 @@ SFLPhoneWindow::SFLPhoneWindow() mMain = new QLabel(this); QPixmap main(JPushButton::transparize(BACKGROUND_IMAGE)); mMain->setPixmap(main); - //mMain->move(100,100); - /* if(main.hasAlpha()) { - setMask(main.mask()); + setMask(*main.mask()); } - */ resize(main.size()); mMain->resize(main.size()); @@ -142,8 +139,8 @@ SFLPhoneWindow::initLineButtons() int ypos = 151; int offset = 31; for(int i = 0; i < NB_PHONELINES; i++) { - PhoneLineButton *line = new PhoneLineButton(QString("images/l%1_off.png").arg(i + 1), - QString("images/l%1_on.png").arg(i + 1), + PhoneLineButton *line = new PhoneLineButton(QString("l%1_off.png").arg(i + 1), + QString("l%1_on.png").arg(i + 1), i, mMain); line->move(xpos, ypos); diff --git a/src/gui/official/TCPSessionIO.cpp b/src/gui/official/TCPSessionIO.cpp index be682479fd..d141f2e963 100644 --- a/src/gui/official/TCPSessionIO.cpp +++ b/src/gui/official/TCPSessionIO.cpp @@ -76,7 +76,7 @@ TCPSessionIO::connect() void TCPSessionIO::sendWaitingRequests() { - _debug("TCPSessionIO: Connected.\n"); + DebugOutput::instance() << QObject::tr("TCPSessionIO: Connected.\n"); QTextStream stream(mSocket); QMutexLocker guard(&mStackMutex); while(mSocket->state() == QSocket::Connected && diff --git a/src/gui/official/TransparentWidget.cpp b/src/gui/official/TransparentWidget.cpp index 6807b34dbb..5107f46ca8 100644 --- a/src/gui/official/TransparentWidget.cpp +++ b/src/gui/official/TransparentWidget.cpp @@ -20,8 +20,11 @@ #include <qbitmap.h> #include <qcolor.h> +#include <qdragobject.h> +#include <qmime.h> #include <iostream> +#include "DebugOutput.hpp" #include "TransparentWidget.hpp" @@ -31,11 +34,8 @@ TransparentWidget::TransparentWidget(const QString &pixmap, { mImage = transparize(pixmap); setPixmap(mImage); - /* - if(mImage.hasAlpha()) { - setMask(mImage.mask()); - } - */ + updateMask(this, mImage); + resize(mImage.size()); } @@ -43,6 +43,25 @@ TransparentWidget::TransparentWidget(QWidget* parent) : QLabel(parent) {} +void +TransparentWidget::updateMask(QWidget *w, QPixmap image) +{ +#ifdef QT3_SUPPORT + if(image.hasAlpha()) { + w->setMask(image.mask()); + } +#else + if(image.mask()) { + w->setMask(*image.mask()); + } +#endif +} + +QPixmap +TransparentWidget::retreive(const QString &image) +{ + return QPixmap::fromMimeSource(image); +} QPixmap TransparentWidget::transparize(const QSize &) @@ -65,8 +84,8 @@ TransparentWidget::~TransparentWidget() QPixmap TransparentWidget::transparize(const QString &image) { - QPixmap p(QPixmap::fromMimeSource(image)); - /* +#ifdef QT3_SUPPORT + QPixmap p(retreive(image)); if (!p.mask()) { if (p.hasAlphaChannel()) { p.setMask(p.alphaChannel()); @@ -75,7 +94,22 @@ TransparentWidget::transparize(const QString &image) p.setMask(p.createHeuristicMask()); } } - */ +#else + // QPixmap p(QPixmap::fromMimeSource(image)); + QImage img(QImage::fromMimeSource(image)); + QPixmap p; + p.convertFromImage(img); + + + QBitmap bm; + if (img.hasAlphaBuffer()) { + bm = img.createAlphaMask(); + } + else { + bm = img.createHeuristicMask(); + } + p.setMask(bm); +#endif return p; } diff --git a/src/gui/official/TransparentWidget.hpp b/src/gui/official/TransparentWidget.hpp index d8626b38f1..7ce9c85d47 100644 --- a/src/gui/official/TransparentWidget.hpp +++ b/src/gui/official/TransparentWidget.hpp @@ -40,9 +40,17 @@ public: TransparentWidget(QWidget *parent); ~TransparentWidget(); + static QPixmap retreive(const QString &size); static QPixmap transparize(const QSize &size); static QPixmap transparize(const QString &image); + /** + * This function will update the mask of the widget + * to the QPixmap mask. + */ + void updateMask(QWidget *w, QPixmap image); + + bool hasAlpha() {return mImage.hasAlpha();} diff --git a/src/gui/official/VolumeControl.cpp b/src/gui/official/VolumeControl.cpp index 8b5ea41777..026b687b15 100644 --- a/src/gui/official/VolumeControl.cpp +++ b/src/gui/official/VolumeControl.cpp @@ -24,7 +24,7 @@ #include "TransparentWidget.hpp" #include "VolumeControl.hpp" -#define SLIDER_IMAGE "images/slider.png" +#define SLIDER_IMAGE "slider.png" VolumeControl::VolumeControl (const QString &pixname, QWidget *parent, @@ -47,8 +47,12 @@ VolumeControl::~VolumeControl() void VolumeControl::resize() { - QPixmap q(TransparentWidget::transparize(SLIDER_IMAGE)); + QPixmap q(QPixmap::fromMimeSource(SLIDER_IMAGE)); setPixmap(q); + if(q.hasAlpha()) { + setMask(*q.mask()); + } + QWidget::resize(q.size()); mMaxPosition = q.height() - mSlider->height(); } diff --git a/src/gui/official/globals.h b/src/gui/official/globals.h index a25d31c4f4..5744341997 100644 --- a/src/gui/official/globals.h +++ b/src/gui/official/globals.h @@ -3,12 +3,6 @@ #define DEBUG -#ifdef DEBUG - #define _debug(...) fprintf(stderr, "[debug] " __VA_ARGS__) -#else - #define _debug(...) -#endif - #define NB_PHONELINES 6 #define PROGNAME "SFLPhone" #define VERSION "0.4.2" diff --git a/src/gui/official/sflphone.pro b/src/gui/official/sflphone.pro index f4eb7ddfaf..fa78c870d0 100644 --- a/src/gui/official/sflphone.pro +++ b/src/gui/official/sflphone.pro @@ -86,6 +86,7 @@ images/setup_on.png \ images/sfl-logo.png \ images/sflphone_logo.png \ images/signalisations.png \ +images/slider.png \ images/transfer_off.png \ images/transfer_on.png \ images/tray-icon.png \ -- GitLab