/* * Hydrogen * Copyright(c) 2002-2007 by Alex >Comix< Cominu [comix@users.sourceforge.net] * http://www.hydrogen-music.org * Copyright 2007 Stéphane Brunner * * 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 St, Fifth Floor, Boston, * MA 02110-1301, USA. */ #include "PixmapWidget.h" #include #include #include namespace LiveMix { PixmapWidget::PixmapWidget(QWidget *pParent) : QWidget(pParent) , m_sPixmapPath("") , __expand_horiz(false) { // draw the background: slower but useful with transparent images! //setAttribute(Qt::WA_NoBackground); __color = QColor(200, 0, 0); } PixmapWidget::~PixmapWidget() {} void PixmapWidget::setColor(const QColor& color) { if (__color == color) { return; } __color = color; update(); } void PixmapWidget::setPixmap(QString sPixmapPath, bool expand_horiz) { if (m_sPixmapPath == sPixmapPath) { return; } m_sPixmapPath = sPixmapPath; __expand_horiz = expand_horiz; bool ok = m_pixmap.load(":/data/" + sPixmapPath); if (!ok) { qDebug() << "error loading: " << ":/data/" + sPixmapPath; } resize(m_pixmap.width(), m_pixmap.height()); update(); } void PixmapWidget::paintEvent(QPaintEvent* ev) { QWidget::paintEvent(ev); QPainter painter(this); if (m_pixmap.isNull()) { painter.fillRect(ev->rect(), __color); } else { if (__expand_horiz) { static int w = 10; static int h = m_pixmap.height(); // central section, scaled painter.drawPixmap(QRect(w, 0, width() - w * 2, h), m_pixmap, QRect(10, 0, w, h)); // left side painter.drawPixmap(QRect(0, 0, w, h), m_pixmap, QRect(0, 0, w, h)); // right side painter.drawPixmap(QRect(width() - w, 0, w, h), m_pixmap, QRect(m_pixmap.width() - w, 0, w, h)); } else { painter.drawPixmap(ev->rect(), m_pixmap, ev->rect()); } } } } ; //LiveMix