diff options
| -rw-r--r-- | lib/soundcore.cpp | 10 | ||||
| -rw-r--r-- | lib/soundcore.h | 7 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/dock.cpp | 344 | ||||
| -rw-r--r-- | src/dock.h | 9 | ||||
| -rw-r--r-- | src/mainvisual.h | 2 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 3 | ||||
| -rw-r--r-- | src/shadedvisual.cpp | 199 | ||||
| -rw-r--r-- | src/shadedvisual.h | 69 | ||||
| -rw-r--r-- | src/skin.cpp | 4 | ||||
| -rw-r--r-- | src/skin.h | 7 | ||||
| -rw-r--r-- | src/src.pro | 8 | ||||
| -rw-r--r-- | src/titlebar.cpp | 155 | ||||
| -rw-r--r-- | src/titlebar.h | 20 | ||||
| -rw-r--r-- | src/titlebarcontrol.cpp | 58 | ||||
| -rw-r--r-- | src/titlebarcontrol.h | 54 |
16 files changed, 745 insertions, 208 deletions
diff --git a/lib/soundcore.cpp b/lib/soundcore.cpp index b94fd223f..6c6f058e7 100644 --- a/lib/soundcore.cpp +++ b/lib/soundcore.cpp @@ -385,6 +385,16 @@ void SoundCore::removeVisual(VisualFactory *factory) Visual::setEnabled(factory, FALSE); } +void SoundCore::removeVisual(Visual *visual) +{ + if (m_visuals.indexOf (visual) != -1) + { + m_visuals.removeAll(visual); + if(m_output) + m_output->removeVisual(visual); + } +} + SoundCore* SoundCore::instance() { return m_instance; diff --git a/lib/soundcore.h b/lib/soundcore.h index e2e8dd566..cd342d677 100644 --- a/lib/soundcore.h +++ b/lib/soundcore.h @@ -134,7 +134,7 @@ public: //visualization /*! - * adds visualization + * adds visualization \b visual */ void addVisualization(Visual *visual); @@ -153,6 +153,11 @@ public: */ void removeVisual(VisualFactory *factory); + /*! + * removes visualization \b visual + */ + void removeVisual(Visual *visual); + static SoundCore* instance(); signals: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ee9f05439..c821a8899 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,6 +76,8 @@ SET(libsrc_SRCS visualmenu.cpp volumebar.cpp fft.c + shadedvisual.cpp + titlebarcontrol.cpp ) SET(libsrc_MOC_HDRS @@ -128,6 +130,8 @@ SET(libsrc_MOC_HDRS version.h visualmenu.h volumebar.h + shadedvisual.h + titlebarcontrol.h ) SET(libsrc_RCCS images/images.qrc stuff.qrc translations/qmmp_locales.qrc) diff --git a/src/dock.cpp b/src/dock.cpp index 2dc064639..2a755a9b9 100644 --- a/src/dock.cpp +++ b/src/dock.cpp @@ -27,16 +27,16 @@ Dock *Dock::pointer = 0; Dock *Dock::getPointer() { - if ( !pointer ) - pointer = new Dock(); - return pointer; + if ( !pointer ) + pointer = new Dock(); + return pointer; } Dock::Dock ( QObject *parent ) - : QObject ( parent ) + : QObject ( parent ) { - pointer = this; - m_mainWidget = 0; + pointer = this; + m_mainWidget = 0; } Dock::~Dock() @@ -44,202 +44,214 @@ Dock::~Dock() void Dock::setMainWidget ( QWidget *widget ) { - m_mainWidget = widget; - m_widgetList.prepend ( widget ); - m_dockedList.prepend ( FALSE ); + m_mainWidget = widget; + m_widgetList.prepend ( widget ); + m_dockedList.prepend ( FALSE ); } QPoint Dock::snap ( QPoint npos, QWidget* mv, QWidget* st ) { - int nx = npos.x() - st->x(); - int ny = abs ( npos.y() - st->y() + mv->height() ); - - if ( abs ( nx ) < 15 && ny < 15 ) //above - npos.rx() = st->x(); - if ( ny < 15 && nx > -mv->width() && nx < st->width() ) - npos.ry() = st->y() - mv->height(); - nx = abs ( npos.x() + mv->width() - st->x() - st->width() ); - if ( nx < 15 && ny < 15 ) - npos.rx() = st->x() + st->width() - mv->width(); - - /***********/ - nx = npos.x() - st->x(); - ny = abs ( npos.y() - st->y() - st->height() ); - - if ( abs ( nx ) < 15 && ny < 15 ) //near - npos.rx() = st->x(); - if ( ny < 15 && nx > -mv->width() && nx < st->width() ) - npos.ry() = st->y() + st->height(); - nx = abs ( npos.x() + mv->width() - st->x() - st->width() ); - if ( nx < 15 && ny < 15 ) - npos.rx() = st->x() + st->width() - mv->width(); - /**************/ - nx = abs ( npos.x() - st->x() + mv->width() ); - ny = npos.y() - st->y(); - - if ( nx < 15 && abs ( ny ) < 15 ) //left - npos.ry() = st->y(); - if ( nx < 15 && ny > -mv->height() && ny < st->height() ) - npos.rx() = st->x() - mv->width(); - - ny = abs ( npos.y() + mv->height() - st->y() - st->height() ); - if ( nx < 15 && ny < 15 ) - npos.ry() = st->y() + st->height() - mv->height(); - /*****************/ - nx = abs ( npos.x() - st->x() - st->width() ); - ny = npos.y() - st->y(); - - if ( nx < 15 && abs ( ny ) < 15 ) //right - npos.ry() = st->y(); - if ( nx < 15 && ny > -mv->height() && ny < st->height() ) - npos.rx() = st->x() + st->width(); - - ny = abs ( npos.y() + mv->height() - st->y() - st->height() ); - if ( nx < 15 && ny < 15 ) - npos.ry() = st->y() + st->height() - mv->height(); - - return ( npos ); + int nx = npos.x() - st->x(); + int ny = abs ( npos.y() - st->y() + mv->height() ); + + if ( abs ( nx ) < 13 && ny < 13 ) //above + npos.rx() = st->x(); + if ( ny < 13 && nx > -mv->width() && nx < st->width() ) + npos.ry() = st->y() - mv->height(); + nx = abs ( npos.x() + mv->width() - st->x() - st->width() ); + if ( nx < 13 && ny < 13 ) + npos.rx() = st->x() + st->width() - mv->width(); + + /***********/ + nx = npos.x() - st->x(); + ny = abs ( npos.y() - st->y() - st->height() ); + + if ( abs ( nx ) < 13 && ny < 13 ) //near + npos.rx() = st->x(); + if ( ny < 13 && nx > -mv->width() && nx < st->width() ) + npos.ry() = st->y() + st->height(); + nx = abs ( npos.x() + mv->width() - st->x() - st->width() ); + if ( nx < 13 && ny < 13 ) + npos.rx() = st->x() + st->width() - mv->width(); + /**************/ + nx = abs ( npos.x() - st->x() + mv->width() ); + ny = npos.y() - st->y(); + + if ( nx < 13 && abs ( ny ) < 13 ) //left + npos.ry() = st->y(); + if ( nx < 13 && ny > -mv->height() && ny < st->height() ) + npos.rx() = st->x() - mv->width(); + + ny = abs ( npos.y() + mv->height() - st->y() - st->height() ); + if ( nx < 13 && ny < 13 ) + npos.ry() = st->y() + st->height() - mv->height(); + /*****************/ + nx = abs ( npos.x() - st->x() - st->width() ); + ny = npos.y() - st->y(); + + if ( nx < 13 && abs ( ny ) < 13 ) //right + npos.ry() = st->y(); + if ( nx < 13 && ny > -mv->height() && ny < st->height() ) + npos.rx() = st->x() + st->width(); + + ny = abs ( npos.y() + mv->height() - st->y() - st->height() ); + if ( nx < 13 && ny < 13 ) + npos.ry() = st->y() + st->height() - mv->height(); + + return ( npos ); } void Dock::addWidget ( QWidget *widget ) { - m_widgetList.append ( widget ); - m_dockedList.append ( FALSE ); - widget->addActions(m_actions); + m_widgetList.append ( widget ); + m_dockedList.append ( FALSE ); + widget->addActions(m_actions); } void Dock::move ( QWidget* mv, QPoint npos ) { - if ( mv == m_mainWidget ) - { - - for ( int i = 1; i<m_widgetList.size(); ++i ) - { - if ( !m_dockedList.at ( i ) ) - { - if ( m_widgetList.at ( i )->isVisible() ) - npos = snap ( npos, mv, m_widgetList.at ( i ) ); - - } - else - { - QPoint pos = QPoint ( npos.x() + x_list.at ( i ), - npos.y() + y_list.at ( i ) ); - for ( int j = 1; j<m_widgetList.size(); ++j ) + if ( mv == m_mainWidget ) + { + + for ( int i = 1; i<m_widgetList.size(); ++i ) + { + if ( !m_dockedList.at ( i ) ) { - if ( !m_dockedList.at ( j ) && m_widgetList.at ( j )->isVisible() ) - { - pos = snap ( pos, m_widgetList.at ( i ), m_widgetList.at ( j ) ); - npos = QPoint ( pos.x() - x_list.at ( i ), - pos.y() - y_list.at ( i ) ); - } + if ( m_widgetList.at ( i )->isVisible() ) + npos = snap ( npos, mv, m_widgetList.at ( i ) ); + } - } - } - mv->move ( npos ); - for ( int i = 1; i<m_widgetList.size(); ++i ) - { - if ( m_dockedList.at ( i ) ) - m_widgetList.at ( i )->move ( npos.x() + x_list.at ( i ), - npos.y() + y_list.at ( i ) ); - } - } - else - { - for ( int i = 0; i<m_widgetList.size(); ++i ) - { - m_dockedList[i] = FALSE; - if ( mv!=m_widgetList.at ( i ) && !m_dockedList.at ( i ) && m_widgetList.at ( i )->isVisible() ) - { - npos = snap ( npos, mv, m_widgetList.at ( i ) ); - } - } - mv->move ( npos ); - } + else + { + QPoint pos = QPoint ( npos.x() + x_list.at ( i ), + npos.y() + y_list.at ( i ) ); + for ( int j = 1; j<m_widgetList.size(); ++j ) + { + if ( !m_dockedList.at ( j ) && m_widgetList.at ( j )->isVisible() ) + { + pos = snap ( pos, m_widgetList.at ( i ), m_widgetList.at ( j ) ); + npos = QPoint ( pos.x() - x_list.at ( i ), + pos.y() - y_list.at ( i ) ); + } + } + } + } + mv->move ( npos ); + for ( int i = 1; i<m_widgetList.size(); ++i ) + { + if ( m_dockedList.at ( i ) ) + m_widgetList.at ( i )->move ( npos.x() + x_list.at ( i ), + npos.y() + y_list.at ( i ) ); + } + } + else + { + for ( int i = 0; i<m_widgetList.size(); ++i ) + { + m_dockedList[i] = FALSE; + if ( mv!=m_widgetList.at ( i ) && !m_dockedList.at ( i ) && m_widgetList.at ( i )->isVisible() ) + { + npos = snap ( npos, mv, m_widgetList.at ( i ) ); + } + } + mv->move ( npos ); + } } void Dock::calculateDistances() { - x_list.clear(); - y_list.clear(); - foreach ( QWidget *w, m_widgetList ) - { - if ( w!=m_mainWidget ) - { - x_list.append ( - m_mainWidget->x() + w->x() ); - y_list.append ( - m_mainWidget->y() + w->y() ); - } - else - { - x_list.prepend ( 0 ); - y_list.prepend ( 0 ); - } - } + x_list.clear(); + y_list.clear(); + foreach ( QWidget *w, m_widgetList ) + { + if ( w!=m_mainWidget ) + { + x_list.append ( - m_mainWidget->x() + w->x() ); + y_list.append ( - m_mainWidget->y() + w->y() ); + } + else + { + x_list.prepend ( 0 ); + y_list.prepend ( 0 ); + } + } } void Dock::updateDock() { - QWidget *mv = m_widgetList.at ( 0 ); - for ( int j = 1; j<m_widgetList.size(); ++j ) - { - QWidget *st = m_widgetList.at ( j ); - m_dockedList[j] = isDocked ( mv, st ); - } - for ( int j = 1; j<m_widgetList.size(); ++j ) - { - if ( m_dockedList[j] ) - for ( int i = 1; i<m_widgetList.size(); ++i ) - { - if ( !m_dockedList[i] ) + QWidget *mv = m_widgetList.at ( 0 ); + for ( int j = 1; j<m_widgetList.size(); ++j ) + { + QWidget *st = m_widgetList.at ( j ); + m_dockedList[j] = isDocked ( mv, st ); + } + for ( int j = 1; j<m_widgetList.size(); ++j ) + { + if ( m_dockedList[j] ) + for ( int i = 1; i<m_widgetList.size(); ++i ) { - mv = m_widgetList.at ( j ); - QWidget *st = m_widgetList.at ( i ); - m_dockedList[i] = isDocked ( mv, st ); + if ( !m_dockedList[i] ) + { + mv = m_widgetList.at ( j ); + QWidget *st = m_widgetList.at ( i ); + m_dockedList[i] = isDocked ( mv, st ); + } } - } - } + } } bool Dock::isDocked ( QWidget* mv, QWidget* st ) { - int nx = mv->x() - st->x(); - int ny = abs ( mv->y() - st->y() + mv->height() ); - if ( ny < 2 && nx > -mv->width() && nx < st->width() ) //above - return TRUE; - - /***********/ - nx = mv->x() - st->x(); - ny = abs ( mv->y() - st->y() - st->height() ); - if ( ny < 2 && nx > -mv->width() && nx < st->width() ) //near - return TRUE; - - /**************/ - nx = abs ( mv->x() - st->x() + mv->width() ); - ny = mv->y() - st->y(); - if ( nx < 2 && ny > -mv->height() && ny < st->height() ) //left - return TRUE; - - /*****************/ - nx = abs ( mv->x() - st->x() - st->width() ); - ny = mv->y() - st->y(); - if ( nx < 2 && ny > -mv->height() && ny < st->height() ) //right - return TRUE; - return FALSE; + int nx = mv->x() - st->x(); + int ny = abs ( mv->y() - st->y() + mv->height() ); + if ( ny < 2 && nx > -mv->width() && nx < st->width() ) //above + return TRUE; + + /***********/ + nx = mv->x() - st->x(); + ny = abs ( mv->y() - st->y() - st->height() ); + if ( ny < 2 && nx > -mv->width() && nx < st->width() ) //near + return TRUE; + + /**************/ + nx = abs ( mv->x() - st->x() + mv->width() ); + ny = mv->y() - st->y(); + if ( nx < 2 && ny > -mv->height() && ny < st->height() ) //left + return TRUE; + + /*****************/ + nx = abs ( mv->x() - st->x() - st->width() ); + ny = mv->y() - st->y(); + if ( nx < 2 && ny > -mv->height() && ny < st->height() ) //right + return TRUE; + return FALSE; } void Dock::addActions ( QList<QAction *> actions ) { - m_actions << actions; - for ( int i = 0; i<m_widgetList.size(); ++i ) - m_widgetList.at ( i )->addActions ( actions ); + m_actions << actions; + for ( int i = 0; i<m_widgetList.size(); ++i ) + m_widgetList.at ( i )->addActions ( actions ); +} + +bool Dock::isUnder(QWidget* upper, QWidget* nether, int dy) +{ + int nx = upper->x() - nether->x(); + return abs (upper->y() + upper->height() -dy - nether->y()) < 2 && + nx > -upper->width() && nx < nether->width(); } -bool Dock::isUnder(QWidget* upper, QWidget* nether) +void Dock::align(QWidget* w, int dy) { - if (!isDocked(upper, nether)) - return FALSE; - return abs (upper->y() + upper->height() - nether->y()) < 2; + for (int i = 0; i<m_dockedList.size(); ++i) + { + if (m_widgetList.at(i) != w && isUnder(w, m_widgetList.at(i), dy)) + { + m_widgetList.at(i)->move(m_widgetList.at(i)->x(), m_widgetList.at(i)->y()+dy); + align(m_widgetList.at(i), dy); + } + } } diff --git a/src/dock.h b/src/dock.h index 95c0e3433..b4b62dda2 100644 --- a/src/dock.h +++ b/src/dock.h @@ -36,6 +36,8 @@ class Dock : public QObject public: Dock(QObject *parent = 0); + ~Dock(); + static Dock *getPointer(); void setMainWidget(QWidget*); void addWidget(QWidget *); @@ -44,12 +46,11 @@ public: void updateDock(); QPoint snap(QPoint, QWidget*, QWidget*); void addActions(QList<QAction *> actions); - - ~Dock(); + void align(QWidget*, int dy); private: bool isDocked(QWidget*, QWidget*); - bool isUnder(QWidget*, QWidget*); + bool isUnder(QWidget*, QWidget*, int); static Dock *pointer; QWidget *m_mainWidget; QList <QWidget *> m_widgetList; @@ -57,8 +58,6 @@ private: QList <int> x_list; QList <int> y_list; QList <QAction *> m_actions; - - }; #endif diff --git a/src/mainvisual.h b/src/mainvisual.h index 6f4b1907a..5357dd310 100644 --- a/src/mainvisual.h +++ b/src/mainvisual.h @@ -82,7 +82,7 @@ public: void add(Buffer *, unsigned long, int, int); void clear(); - void paintEvent( QPaintEvent * ); + void paintEvent(QPaintEvent *); protected: virtual void hideEvent (QHideEvent *); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 324c8521b..30470882d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -106,6 +106,7 @@ MainWindow::MainWindow(const QStringList& args, QWidget *parent) createActions(); + m_core = new SoundCore(this); m_titlebar = new TitleBar(this); m_titlebar->move(0,0); m_titlebar->show(); @@ -124,7 +125,6 @@ MainWindow::MainWindow(const QStringList& args, QWidget *parent) m_vis = MainVisual::getPointer(); - m_core = new SoundCore(this); m_core->addVisualization(m_vis); m_core->showVisualization(this); @@ -306,6 +306,7 @@ void MainWindow::showOutputState(const OutputState &st) display->setInfo(st); m_playlist->setInfo(st, m_core->length(), m_playListModel->totalLength()); + m_titlebar->setInfo(st); switch ((int) st.type()) { case OutputState::Playing: diff --git a/src/shadedvisual.cpp b/src/shadedvisual.cpp new file mode 100644 index 000000000..e7bb5d683 --- /dev/null +++ b/src/shadedvisual.cpp @@ -0,0 +1,199 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QTimer> +#include <math.h> +#include "skin.h" +#include "mainvisual.h" +#include "inlines.h" + + +#include "shadedvisual.h" + +ShadedVisual::ShadedVisual(QWidget *parent) + : Visual(parent) +{ + setFixedSize(38,5); + m_pixmap = QPixmap (38,5); + m_skin = Skin::getPointer(); + m_timer = new QTimer(this); + connect(m_timer, SIGNAL (timeout()), this, SLOT (timeout())); + connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); + m_timer->setInterval(50); + m_timer->start(); + clear(); +} + + +ShadedVisual::~ShadedVisual() +{ +} + +void ShadedVisual::add(Buffer *b, unsigned long w, int c, int p) +{ + if (!m_timer->isActive ()) + return; + long len = b->nbytes, cnt; + short *l = 0, *r = 0; + + len /= c; + len /= ( p / 8 ); + if ( len > 512 ) + len = 512; + cnt = len; + + if ( c == 2 ) + { + l = new short[len]; + r = new short[len]; + + if ( p == 8 ) + stereo16_from_stereopcm8 ( l, r, b->data, cnt ); + else if ( p == 16 ) + stereo16_from_stereopcm16 ( l, r, ( short * ) b->data, cnt ); + } + else if ( c == 1 ) + { + l = new short[len]; + + if ( p == 8 ) + mono16_from_monopcm8 ( l, b->data, cnt ); + else if ( p == 16 ) + mono16_from_monopcm16 ( l, ( short * ) b->data, cnt ); + } + else + len = 0; + + if (len) + m_nodes.append (new VisualNode (l, r, len, w)); +} + +void ShadedVisual::clear() +{ + while (!m_nodes.isEmpty()) + m_nodes.removeFirst(); + m_l = 0; + m_r = 0; + m_pixmap.fill(m_skin->getVisColor(0)); + update(); +}; + +void ShadedVisual::timeout() +{ + VisualNode *node = 0; + m_pixmap.fill(m_skin->getVisColor(0)); + + if ( /*playing &&*/ output()) + { + //output()->mutex()->lock (); + //long olat = output()->latency(); + //long owrt = output()->written(); + //output()->mutex()->unlock(); + + //long synctime = owrt < olat ? 0 : owrt - olat; + + mutex()->lock (); + VisualNode *prev = 0; + while ((!m_nodes.isEmpty())) + { + node = m_nodes.takeFirst(); + /*if ( node->offset > synctime ) + break;*/ + + if (prev) + delete prev; + prev = node; + } + mutex()->unlock(); + node = prev; + } + + if (!node) + return; + process (node); + delete node; + QPainter p(&m_pixmap); + draw (&p); + update(); +} + +void ShadedVisual::process (VisualNode *node) +{ + if (!node) + return; + + int step = (node->length << 8)/74; + int pos = 0; + int l = 0; + int r = 0; + int j_l = 0, j_r = 0; + + for (int i = 0; i < 75; ++i) + { + pos += step; + j_l = abs((node->left[pos >> 8] >> 12)); + j_r = abs((node->right[pos >> 8] >> 12)); + + if (j_l > 15) + j_l = 15; + if (j_r > 15) + j_r = 15; + l = qMax(l, j_l); + r = qMax(r, j_r); + } + m_l -= 0.5; + m_l = m_l > l ? m_l : l; + m_r -= 0.5; + m_r = m_r > r ? m_r : r; +} + +void ShadedVisual::draw (QPainter *p) +{ + for(int i = 0; i < m_l; ++i) + { + p->fillRect (i*3, 0, 3, 2, QBrush(m_skin->getVisColor (17-i))); + } + for(int i = 0; i < m_r; ++i) + { + p->fillRect (i*3, 3, 3, 2, QBrush(m_skin->getVisColor (17-i))); + } +} + +void ShadedVisual::paintEvent (QPaintEvent *) +{ + QPainter painter (this); + painter.drawPixmap (0,0,m_pixmap); +} + +void ShadedVisual::hideEvent (QHideEvent *) +{ + m_timer->stop(); +} + +void ShadedVisual::showEvent (QShowEvent *) +{ + m_timer->start(); +} + +void ShadedVisual::updateSkin() +{ + clear(); +} + diff --git a/src/shadedvisual.h b/src/shadedvisual.h new file mode 100644 index 000000000..e46331ecb --- /dev/null +++ b/src/shadedvisual.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef SHADEDVISUAL_H +#define SHADEDVISUAL_H + + +#include <QPainter> +#include <visual.h> +#include <buffer.h> + +class QTimer; +class QPixmap; + +class Skin; +class VisualNode; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class ShadedVisual : public Visual +{ + Q_OBJECT +public: + ShadedVisual(QWidget *parent = 0); + + ~ShadedVisual(); + + void add(Buffer *, unsigned long, int, int); + void clear(); + + void paintEvent (QPaintEvent *); + void hideEvent (QHideEvent *); + void showEvent (QShowEvent *); + +public slots: + void timeout(); + +private slots: + void updateSkin(); + +private: + void process (VisualNode *node); + void draw (QPainter *); + Skin *m_skin; + QTimer *m_timer; + QPixmap m_pixmap; + QList <VisualNode*> m_nodes; + double m_l, m_r; + +}; + +#endif diff --git a/src/skin.cpp b/src/skin.cpp index 135fa9372..0ea4e366e 100644 --- a/src/skin.cpp +++ b/src/skin.cpp @@ -165,8 +165,8 @@ void Skin::loadTitleBar() buttons[BT_SHADE2_P] = pixmap->copy ( 9,27,9,9 ); titlebar[TITLEBAR_A] = pixmap->copy ( 27, 0,275,14 ); titlebar[TITLEBAR_I] = pixmap->copy ( 27,15,275,14 ); - titlebar[STATUSBAR_A] = pixmap->copy ( 27,29,275,14 ); - titlebar[STATUSBAR_I] = pixmap->copy ( 27,42,275,14 ); + titlebar[TITLEBAR_SHADED_A] = pixmap->copy ( 27,29,275,14 ); + titlebar[TITLEBAR_SHADED_I] = pixmap->copy ( 27,42,275,14 ); delete pixmap; } diff --git a/src/skin.h b/src/skin.h index 4d5416cb9..614cd6dc4 100644 --- a/src/skin.h +++ b/src/skin.h @@ -153,6 +153,9 @@ public: BT_SHADE1_P, BT_SHADE2_N, BT_SHADE2_P, + BT_CLOSE_SHADED_N, + BT_CLOSE_SHADED_P, + /* posbar.* */ BT_POSBAR_N, BT_POSBAR_P, @@ -211,8 +214,8 @@ public: { TITLEBAR_A = 0, TITLEBAR_I, - STATUSBAR_A, - STATUSBAR_I + TITLEBAR_SHADED_A, + TITLEBAR_SHADED_I, }; enum PlayList { diff --git a/src/src.pro b/src/src.pro index 26e584144..b704ee507 100644 --- a/src/src.pro +++ b/src/src.pro @@ -139,8 +139,12 @@ INSTALLS += target HEADERS += addurldialog.h \ skinreader.h \ - visualmenu.h + visualmenu.h \ + titlebarcontrol.h \ + shadedvisual.h SOURCES += addurldialog.cpp \ skinreader.cpp \ - visualmenu.cpp + visualmenu.cpp \ + titlebarcontrol.cpp \ + shadedvisual.cpp FORMS += addurldialog.ui diff --git a/src/titlebar.cpp b/src/titlebar.cpp index 189105f06..bdbd86b2e 100644 --- a/src/titlebar.cpp +++ b/src/titlebar.cpp @@ -22,18 +22,26 @@ #include <QApplication> #include <QMouseEvent> #include <QMenu> +#include <QSettings> -#include "titlebar.h" +#include <soundcore.h> +#include "symboldisplay.h" #include "skin.h" #include "button.h" #include "dock.h" +#include "titlebarcontrol.h" +#include "shadedvisual.h" +#include "titlebar.h" TitleBar::TitleBar(QWidget *parent) : PixmapWidget(parent) { + m_align = FALSE; m_skin = Skin::getPointer(); setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_A)); m_mw = qobject_cast<MainWindow*>(parent); + m_shaded = FALSE; + m_currentTime = 0; //buttons m_menu = new Button(this,Skin::BT_MENU_N,Skin::BT_MENU_P); connect(m_menu,SIGNAL(clicked()),this,SLOT(showMainMenu())); @@ -43,36 +51,40 @@ TitleBar::TitleBar(QWidget *parent) connect(m_minimize, SIGNAL(clicked()), m_mw, SLOT(showMinimized())); m_shade = new Button(this,Skin::BT_SHADE1_N,Skin::BT_SHADE1_P); m_shade->move(254,3); + connect(m_shade, SIGNAL(clicked()), SLOT(shade())); m_close = new Button(this,Skin::BT_CLOSE_N,Skin::BT_CLOSE_P); m_close->move(264,3); connect(m_close, SIGNAL(clicked()), m_mw, SLOT(handleCloseRequest())); setActive(FALSE); connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); + + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + if (settings.value("Display/shaded", FALSE).toBool()) + shade(); + m_align = TRUE; } TitleBar::~TitleBar() -{} - - +{ + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + settings.setValue("Display/shaded", m_shaded); +} void TitleBar::mousePressEvent(QMouseEvent* event) { - switch((int) event->button ()) + switch ((int) event->button ()) + { + case Qt::LeftButton: { - case Qt::LeftButton: - { - m_pos = event->pos(); - PlayList *pl = m_mw->getPLPointer(); - Dock::getPointer()->calculateDistances(); - x_diff = - m_mw->x() + pl->x(); - y_diff = - m_mw->y() + pl->y(); - break; - } - case Qt::RightButton: - { - m_mw->menu()->exec(event->globalPos()); - } + m_pos = event->pos(); + Dock::getPointer()->calculateDistances(); + break; + } + case Qt::RightButton: + { + m_mw->menu()->exec(event->globalPos()); + } } } @@ -88,20 +100,36 @@ void TitleBar::mouseMoveEvent(QMouseEvent* event) void TitleBar::setActive(bool a) { - if(a) + if (a) { - setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_A)); + if (m_shaded) + { + setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_SHADED_A)); + m_shade2->show(); + } + else + { + setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_A)); + m_shade->show(); + } m_menu->show(); m_minimize->show(); - m_shade->show(); m_close->show(); } else { - setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_I)); + if (m_shaded) + { + setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_SHADED_I)); + m_shade2->hide(); + } + else + { + setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_I)); + m_shade->hide(); + } m_menu->hide(); m_minimize->hide(); - m_shade->hide(); m_close->hide(); } } @@ -115,3 +143,84 @@ void TitleBar::showMainMenu() { m_mw->menu()->exec(m_menu->mapToGlobal(m_menu->pos())); } + +void TitleBar::shade() +{ + m_shaded = !m_shaded; + + if (m_shaded) + { + m_mw->setFixedSize(275,14); + setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_SHADED_A)); + m_shade->hide(); + m_shade2 = new Button(this,Skin::BT_SHADE2_N, Skin::BT_SHADE2_P); + m_shade2->move(254,3); + connect(m_shade2, SIGNAL(clicked()), SLOT(shade())); + m_shade2->show(); + m_currentTime = new SymbolDisplay(this, 6); + m_currentTime->move(127,4); + m_currentTime->show(); + m_currentTime->display("--:--"); + m_control = new TitleBarControl(this); + m_control->move(168,2); + m_control->show(); + connect (m_control, SIGNAL (nextClicked()), parent(), SLOT (next())); + connect (m_control, SIGNAL (previousClicked()), parent(), SLOT (previous())); + connect (m_control, SIGNAL (playClicked()), parent(), SLOT (play())); + connect (m_control, SIGNAL (pauseClicked()), parent(), SLOT (pause())); + connect (m_control, SIGNAL (stopClicked()), parent(), SLOT (stop())); + connect (m_control, SIGNAL (ejectClicked()), parent(), SLOT (addFile())); + m_visual = new ShadedVisual(this); + SoundCore::instance()->addVisualization(m_visual); + m_visual->show(); + m_visual->move(79,5); + } + else + { + m_mw->setFixedSize(275,116); + setPixmap(m_skin->getTitleBar(Skin::TITLEBAR_A)); + delete m_shade2; + delete m_currentTime; + delete m_control; + SoundCore::instance()->removeVisual(m_visual); + delete m_visual; + m_shade2 = 0; + m_currentTime = 0; + m_shade->show(); + } + if(m_align) + Dock::getPointer()->align(m_mw, m_shaded? -102: 102); +} + +QString TitleBar::formatTime ( int sec ) +{ + int minutes = sec / 60; + int seconds = sec % 60; + + QString str_minutes = QString::number ( minutes ); + QString str_seconds = QString::number ( seconds ); + + if ( minutes < 10 ) str_minutes.prepend ( "0" ); + if ( seconds < 10 ) str_seconds.prepend ( "0" ); + + return str_minutes + ":" + str_seconds; +} + +void TitleBar::setInfo(const OutputState &st) +{ + if (!m_currentTime) + return; + switch ( ( int ) st.type() ) + { + case OutputState::Info: + { + m_currentTime->display(formatTime(st.elapsedSeconds())); + break; + } + case OutputState::Stopped: + { + m_currentTime->display("--:--"); + break; + } + } +} diff --git a/src/titlebar.h b/src/titlebar.h index 1589effc0..4428a188c 100644 --- a/src/titlebar.h +++ b/src/titlebar.h @@ -21,11 +21,12 @@ #define TITLEBAR_H #include <QMainWindow> -#include "pixmapwidget.h" +#include <QPoint> +#include "pixmapwidget.h" #include "playlist.h" -#include <QPoint> #include "mainwindow.h" + /** @author Ilya Kotov <forkotov02@hotmail.ru> */ @@ -34,7 +35,9 @@ class QMouseEvent; class Skin; class Button; - +class SymbolDisplay; +class TitleBarControl; +class ShadedVisual; class TitleBar : public PixmapWidget { @@ -45,10 +48,12 @@ public: ~TitleBar(); void setActive(bool); + void setInfo(const OutputState &st); private slots: void updateSkin(); void showMainMenu(); + void shade(); private: Skin *m_skin; @@ -57,9 +62,14 @@ private: Button *m_menu; Button *m_minimize; Button *m_shade; + Button *m_shade2; Button *m_close; - int x_diff, y_diff; - + SymbolDisplay *m_currentTime; + QString formatTime (int); + bool m_shaded; + bool m_align; + TitleBarControl *m_control; + ShadedVisual *m_visual; protected: void mousePressEvent(QMouseEvent*); diff --git a/src/titlebarcontrol.cpp b/src/titlebarcontrol.cpp new file mode 100644 index 000000000..8238c287a --- /dev/null +++ b/src/titlebarcontrol.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QMouseEvent> + +#include "titlebarcontrol.h" + +TitleBarControl::TitleBarControl(QWidget *parent) + : QWidget(parent) +{ + //setAutoFillBackground(TRUE); + setFixedSize(57,10); +} + + +TitleBarControl::~TitleBarControl() +{ +} + +void TitleBarControl::mousePressEvent (QMouseEvent *) +{} + +void TitleBarControl::mouseReleaseEvent (QMouseEvent * event) +{ + QPoint pt = event->pos(); + if(QRect(0,0,8,10).contains(pt)) + emit previousClicked(); + else if(QRect(8,0,11,10).contains(pt)) + emit playClicked(); + else if(QRect(19,0,10,10).contains(pt)) + emit pauseClicked(); + else if(QRect(29,0,8,10).contains(pt)) + emit stopClicked(); + else if(QRect(37,0,10,10).contains(pt)) + emit nextClicked(); + else if(QRect(47,0,10,10).contains(pt)) + emit ejectClicked(); +} + +void TitleBarControl::mouseMoveEvent(QMouseEvent*) +{} diff --git a/src/titlebarcontrol.h b/src/titlebarcontrol.h new file mode 100644 index 000000000..c368b2186 --- /dev/null +++ b/src/titlebarcontrol.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef TITLEBARCONTROL_H +#define TITLEBARCONTROL_H + +#include <QWidget> + +class QMouseEvent; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class TitleBarControl : public QWidget +{ +Q_OBJECT +public: + TitleBarControl(QWidget *parent = 0); + ~TitleBarControl(); + +signals: + void previousClicked(); + void nextClicked(); + void pauseClicked(); + void playClicked(); + void stopClicked(); + void ejectClicked(); + +protected: + void mousePressEvent(QMouseEvent*); + void mouseReleaseEvent(QMouseEvent*); + void mouseMoveEvent(QMouseEvent*); + + + +}; + +#endif |
