aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Ui/skinned
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-02-15 17:22:04 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-02-15 17:22:04 +0000
commit631f5b826ce2547fa55a22133e95f232a03c4b3f (patch)
tree90a0f5ffa6b1f3fa5c655c171bf31bddb2080c18 /src/plugins/Ui/skinned
parent14be2d439ed0bf0b3d1389bc6b9174808606974c (diff)
downloadqmmp-631f5b826ce2547fa55a22133e95f232a03c4b3f.tar.gz
qmmp-631f5b826ce2547fa55a22133e95f232a03c4b3f.tar.bz2
qmmp-631f5b826ce2547fa55a22133e95f232a03c4b3f.zip
moved drawing functions to separate class
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4725 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Ui/skinned')
-rw-r--r--src/plugins/Ui/skinned/listwidget.cpp136
-rw-r--r--src/plugins/Ui/skinned/listwidget.h19
-rw-r--r--src/plugins/Ui/skinned/listwidgetdrawer.cpp166
-rw-r--r--src/plugins/Ui/skinned/listwidgetdrawer.h92
-rw-r--r--src/plugins/Ui/skinned/skinned.pro6
5 files changed, 292 insertions, 127 deletions
diff --git a/src/plugins/Ui/skinned/listwidget.cpp b/src/plugins/Ui/skinned/listwidget.cpp
index 975354b81..5c2ea79e3 100644
--- a/src/plugins/Ui/skinned/listwidget.cpp
+++ b/src/plugins/Ui/skinned/listwidget.cpp
@@ -92,6 +92,7 @@ void ListWidget::readSettings()
if (m_update)
{
+ m_drawer.readSettings();
delete m_metrics;
delete m_extra_metrics;
m_metrics = new QFontMetrics(m_font);
@@ -132,7 +133,7 @@ int ListWidget::anchorIndex() const
void ListWidget::setAnchorIndex(int index)
{
m_anchor_index = index;
- update();
+ updateList(PlayListModel::CURRENT);
}
QMenu *ListWidget::menu()
@@ -167,21 +168,21 @@ void ListWidget::paintEvent(QPaintEvent *)
for (int i = 0; i < m_rows.size(); ++i )
{
- drawBackground(&painter, i);
+ m_drawer.drawBackground(&painter, m_rows[i]);
- if(m_rows[i]->separator)
+ if(m_rows[i]->flags & ListWidgetRow::GROUP)
{
- drawSeparator(&painter, m_rows[i], rtl);
+ m_drawer.drawSeparator(&painter, m_number_width, m_rows[i], rtl);
continue;
}
- drawTrack(&painter, m_rows[i], rtl);
+ m_drawer.drawTrack(&painter, m_number_width, m_rows[i], rtl);
}
//draw drop line
if(m_drop_index != INVALID_INDEX)
{
painter.setPen(m_current);
- painter.drawLine (6, (m_drop_index - m_first) * (m_metrics->lineSpacing() + 2),
+ painter.drawLine (6, (m_drop_index - m_first) * (m_metrics->lineSpacing() + 1),
width() - 4 , (m_drop_index - m_first) * (m_metrics->lineSpacing() + 2));
}
//draw line
@@ -220,12 +221,13 @@ void ListWidget::mousePressEvent(QMouseEvent *e)
{
if(!m_model->isSelected(index))
{
+ m_anchor_index = m_pressed_index;
m_model->clearSelection();
m_model->setSelected(index, true);
}
- m_anchor_index = m_pressed_index;
if(m_model->isGroup(index) && m_model->selectedTracks().isEmpty())
{
+ m_anchor_index = m_pressed_index;
PlayListGroup *group = m_model->group(index);
m_model->setSelected(group->tracks());
}
@@ -242,11 +244,13 @@ void ListWidget::mousePressEvent(QMouseEvent *e)
if ((Qt::ShiftModifier & e->modifiers()))
{
- m_model->setSelected(m_pressed_index, m_anchor_index, true);
+ int prev_anchor_index = m_anchor_index;
m_anchor_index = m_pressed_index;
+ m_model->setSelected(m_pressed_index, prev_anchor_index, true);
}
else //ShiftModifier released
{
+ m_anchor_index = m_pressed_index;
if ((Qt::ControlModifier & e->modifiers()))
{
m_model->setSelected(index, !m_model->isSelected(index));
@@ -256,7 +260,7 @@ void ListWidget::mousePressEvent(QMouseEvent *e)
m_model->clearSelection();
m_model->setSelected(index, true);
}
- m_anchor_index = m_pressed_index;
+
}
update();
}
@@ -357,6 +361,12 @@ void ListWidget::updateList(int flags)
for(int i = 0; i < items.count(); ++i)
{
ListWidgetRow *row = m_rows[i];
+ items[i]->isSelected() ? row->flags |= ListWidgetRow::SELECTED :
+ row->flags &= ~ListWidgetRow::SELECTED;
+
+ i == (m_anchor_index - m_first) ? row->flags |= ListWidgetRow::ANCHOR :
+ row->flags &= ~ListWidgetRow::ANCHOR;
+
row->selected = items[i]->isSelected();
if(flags == PlayListModel::SELECTION)
@@ -364,10 +374,16 @@ void ListWidget::updateList(int flags)
row->bgY = i * (m_metrics->lineSpacing() + 1);
row->textY = i * (m_metrics->lineSpacing() + 1) + m_metrics->lineSpacing() - m_metrics->descent();
+ row->rect = QRect(5, i * (m_metrics->lineSpacing() + 1), width() - 10, m_metrics->lineSpacing());
row->title = items[i]->formattedTitle();
row->current = (m_first + i) == m_model->currentIndex();
+
+ (m_first + i) == m_model->currentIndex() ? row->flags |= ListWidgetRow::CURRENT :
+ row->flags &= ~ListWidgetRow::CURRENT;
+
if(items[i]->isGroup())
{
+ row->flags |= ListWidgetRow::GROUP;
row->separator = true;
row->number = 0;
row->length.clear();
@@ -376,6 +392,7 @@ void ListWidget::updateList(int flags)
}
else
{
+ row->flags &= ~ListWidgetRow::GROUP;
row->separator = false;
//optimization: reduces number of PlaListModel::numberOfTrack(int) calls
if(!prev_number)
@@ -435,104 +452,6 @@ void ListWidget::scrollToCurrent()
updateList(PlayListModel::CURRENT | PlayListModel::STRUCTURE);
}
-//drawing functions
-void ListWidget::drawBackground(QPainter *painter, int i)
-{
- if (m_show_anchor && i == m_anchor_index - m_first)
- {
- painter->setBrush(m_rows[i]->selected ? m_selected_bg : m_normal_bg);
- painter->setPen(m_normal);
- painter->drawRect (6, m_rows[i]->bgY, width() - 10,
- m_metrics->lineSpacing());
- }
- else if (m_rows[i]->selected)
- {
- painter->setBrush(QBrush(m_selected_bg));
- painter->setPen(m_selected_bg);
- painter->drawRect (6, m_rows[i]->bgY, width() - 10,
- m_metrics->lineSpacing());
- }
-}
-
-void ListWidget::drawSeparator(QPainter *painter, ListWidgetRow *row, bool rtl)
-{
- int sx = 55;
-
- painter->setPen(m_normal);
-
- if(m_number_width)
- sx += m_number_width + m_metrics->width("9");
- if(rtl)
- sx = width() - sx - m_metrics->width(row->title) - 5;
-
- painter->drawText(sx, row->textY, row->title);
-
- int sy = row->textY - m_metrics->lineSpacing()/2 + 2;
-
- if(rtl)
- {
- painter->drawLine(10, sy, sx - 5, sy);
- painter->drawLine(sx + m_metrics->width(row->title) + 5, sy,
- sx + m_metrics->width(row->title) + 35, sy);
- }
- else
- {
- painter->drawLine(sx - 45, sy, sx - 5, sy);
- painter->drawLine(sx + m_metrics->width(row->title) + 5, sy,
- width() - 10, sy);
- }
-}
-
-void ListWidget::drawTrack(QPainter *painter, ListWidgetRow *row, bool rtl)
-{
- int sx = 0;
-
- painter->setPen(row->current ? m_current : m_normal);
-
- if(m_number_width)
- {
- QString number = QString("%1").arg(row->number);
- sx = 10 + m_number_width - m_metrics->width(number);
- if(rtl)
- sx = width() - sx - m_metrics->width(number);
-
- painter->drawText(sx, row->textY, number);
-
- sx = 10 + m_number_width + m_metrics->width("9");
- if(rtl)
- sx = width() - sx - m_metrics->width(row->title);
- }
- else
- {
- sx = rtl ? width() - 10 - m_metrics->width(row->title) : 10;
- }
-
- painter->drawText(sx, row->textY, row->title);
-
- QString extra_string = row->extraString;
-
- if(!extra_string.isEmpty())
- {
- painter->setFont(m_extra_font);
-
- if(row->length.isEmpty())
- {
- sx = rtl ? 7 : width() - 7 - m_extra_metrics->width(extra_string);
- painter->drawText(sx, row->textY, extra_string);
- }
- else
- {
- sx = width() - 10 - m_extra_metrics->width(extra_string) - m_metrics->width(row->length);
- if(rtl)
- sx = width() - sx - m_extra_metrics->width(extra_string);
- painter->drawText(sx, row->textY, extra_string);
- }
- painter->setFont(m_font);
- }
- sx = rtl ? 9 : width() - 7 - m_metrics->width(row->length);
- painter->drawText(sx, row->textY, row->length);
-}
-
void ListWidget::setModel(PlayListModel *selected, PlayListModel *previous)
{
if(previous)
@@ -568,6 +487,7 @@ void ListWidget::scroll(int sc)
void ListWidget::updateSkin()
{
loadColors();
+ m_drawer.loadColors();
update();
}
@@ -665,6 +585,7 @@ void ListWidget::mouseMoveEvent(QMouseEvent *e)
if (INVALID_INDEX != index)
{
+ m_anchor_index = index;
SimpleSelection sel = m_model->getSelection(m_pressed_index);
if(sel.count() > 1 && m_scroll_direction == TOP)
{
@@ -680,7 +601,6 @@ void ListWidget::mouseMoveEvent(QMouseEvent *e)
m_prev_y = e->y();
m_pressed_index = index;
- m_anchor_index = index;
}
}
else if(m_popupWidget)
diff --git a/src/plugins/Ui/skinned/listwidget.h b/src/plugins/Ui/skinned/listwidget.h
index bb6ddcc4c..79967e944 100644
--- a/src/plugins/Ui/skinned/listwidget.h
+++ b/src/plugins/Ui/skinned/listwidget.h
@@ -24,6 +24,7 @@
#include <QDir>
#include <QContextMenuEvent>
#include <QPen>
+#include "listwidgetdrawer.h"
class QFont;
class QFontMetrics;
@@ -97,27 +98,10 @@ private slots:
void scrollToCurrent();
private:
- struct ListWidgetRow
- {
- QString title;
- QString length;
- QString extraString;
- int number;
- bool separator;
- bool selected;
- bool current;
- //geometry
- int bgY; //top of the background
- int textY; //base line of the text
- };
enum ScrollDirection
{
NONE = 0,TOP,DOWN
};
-
- void drawBackground(QPainter *painter, int i);
- void drawSeparator(QPainter *painter, ListWidgetRow *row, bool rtl);
- void drawTrack(QPainter *painter, ListWidgetRow *row, bool rtl);
void loadColors();
/*!
* Returns string with queue number or(and) repeate flag for the item number \b i.
@@ -151,6 +135,7 @@ private:
QmmpUiSettings *m_ui_settings;
PlayListPopup::PopupWidget *m_popupWidget;
QTimer *m_timer;
+ ListWidgetDrawer m_drawer;
};
#endif
diff --git a/src/plugins/Ui/skinned/listwidgetdrawer.cpp b/src/plugins/Ui/skinned/listwidgetdrawer.cpp
new file mode 100644
index 000000000..3a2e15edb
--- /dev/null
+++ b/src/plugins/Ui/skinned/listwidgetdrawer.cpp
@@ -0,0 +1,166 @@
+/***************************************************************************
+ * Copyright (C) 2015 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include <QSettings>
+#include <QPainter>
+#include <QApplication>
+#include <qmmp/qmmp.h>
+#include "skin.h"
+#include "listwidgetdrawer.h"
+
+ListWidgetDrawer::ListWidgetDrawer()
+{
+ m_skin = Skin::instance();
+ m_update = false;
+ readSettings();
+ loadColors();
+}
+
+ListWidgetDrawer::~ListWidgetDrawer()
+{
+ if(m_metrics)
+ delete m_metrics;
+ if(m_extra_metrics)
+ delete m_extra_metrics;
+}
+
+void ListWidgetDrawer::readSettings()
+{
+ QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
+ settings.beginGroup("Skinned");
+ m_show_anchor = settings.value("pl_show_anchor", false).toBool();
+ m_font.fromString(settings.value("pl_font", QApplication::font().toString()).toString());
+ m_extra_font = m_font;
+ m_extra_font.setPointSize(m_font.pointSize() - 1);
+ if (m_update)
+ {
+ delete m_metrics;
+ delete m_extra_metrics;
+ }
+ m_update = true;
+ m_metrics = new QFontMetrics(m_font);
+ m_extra_metrics = new QFontMetrics(m_extra_font);
+}
+
+void ListWidgetDrawer::loadColors()
+{
+ m_normal.setNamedColor(m_skin->getPLValue("normal"));
+ m_current.setNamedColor(m_skin->getPLValue("current"));
+ m_normal_bg.setNamedColor(m_skin->getPLValue("normalbg"));
+ m_selected_bg.setNamedColor(m_skin->getPLValue("selectedbg"));
+}
+
+void ListWidgetDrawer::drawBackground(QPainter *painter, ListWidgetRow *row)
+{
+ painter->setBrush((row->flags & ListWidgetRow::SELECTED) ? m_selected_bg : m_normal_bg);
+
+ if(m_show_anchor && (row->flags & ListWidgetRow::ANCHOR))
+ {
+ painter->setPen(m_normal);
+ }
+ else if(row->flags & ListWidgetRow::SELECTED)
+ {
+ painter->setPen(m_selected_bg);
+ }
+ else
+ {
+ painter->setPen(m_normal_bg);
+ }
+ painter->drawRect(row->rect);
+}
+
+void ListWidgetDrawer::drawSeparator(QPainter *painter, int m_number_width, ListWidgetRow *row, bool rtl)
+{
+ int sx = row->rect.x() + 50;
+
+ painter->setPen(m_normal);
+
+ if(m_number_width)
+ sx += m_number_width + m_metrics->width("9");
+ if(rtl)
+ sx = row->rect.right() - sx - m_metrics->width(row->title);
+
+ painter->drawText(sx, row->textY, row->title);
+
+ int sy = row->textY - m_metrics->lineSpacing()/2 + 2;
+
+ if(rtl)
+ {
+ painter->drawLine(10, sy, sx - 5, sy);
+ painter->drawLine(sx + m_metrics->width(row->title) + 5, sy,
+ sx + m_metrics->width(row->title) + 35, sy);
+ }
+ else
+ {
+ painter->drawLine(sx - 45, sy, sx - 5, sy);
+ painter->drawLine(sx + m_metrics->width(row->title) + 5, sy,
+ row->rect.width(), sy);
+ }
+}
+
+void ListWidgetDrawer::drawTrack(QPainter *painter, int m_number_width, ListWidgetRow *row, bool rtl)
+{
+ int sx = 0;
+
+ painter->setPen(row->current ? m_current : m_normal);
+
+ if(m_number_width)
+ {
+ QString number = QString("%1").arg(row->number);
+ sx = 10 + m_number_width - m_metrics->width(number);
+ if(rtl)
+ sx = row->rect.right() - sx - m_metrics->width(number);
+
+ painter->drawText(sx, row->textY, number);
+
+ sx = 10 + m_number_width + m_metrics->width("9");
+ if(rtl)
+ sx = row->rect.right() - sx - m_metrics->width(row->title);
+ }
+ else
+ {
+ sx = rtl ? row->rect.right() - 10 - m_metrics->width(row->title) : 10;
+ }
+
+ painter->drawText(sx, row->textY, row->title);
+
+ QString extra_string = row->extraString;
+
+ if(!extra_string.isEmpty())
+ {
+ painter->setFont(m_extra_font);
+
+ if(row->length.isEmpty())
+ {
+ sx = rtl ? 7 : row->rect.right() - 7 - m_extra_metrics->width(extra_string);
+ painter->drawText(sx, row->textY, extra_string);
+ }
+ else
+ {
+ sx = row->rect.right() - 10 - m_extra_metrics->width(extra_string) - m_metrics->width(row->length);
+ if(rtl)
+ sx = row->rect.right() - sx - m_extra_metrics->width(extra_string);
+ painter->drawText(sx, row->textY, extra_string);
+ }
+ painter->setFont(m_font);
+ }
+ sx = rtl ? 9 : row->rect.right() - 7 - m_metrics->width(row->length);
+ painter->drawText(sx, row->textY, row->length);
+}
diff --git a/src/plugins/Ui/skinned/listwidgetdrawer.h b/src/plugins/Ui/skinned/listwidgetdrawer.h
new file mode 100644
index 000000000..717401d1b
--- /dev/null
+++ b/src/plugins/Ui/skinned/listwidgetdrawer.h
@@ -0,0 +1,92 @@
+/***************************************************************************
+ * Copyright (C) 2015 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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef LISTWIDGETDRAWER_H
+#define LISTWIDGETDRAWER_H
+
+#include <QString>
+#include <QColor>
+#include <QRect>
+#include <QFontMetrics>
+
+class Skin;
+class QPainter;
+
+struct ListWidgetRow
+{
+ ListWidgetRow()
+ {
+ flags = NO_FLAGS;
+ }
+ QString title;
+ QString length;
+ QString extraString;
+ int number;
+ enum
+ {
+ NO_FLAGS = 0x00,
+ GROUP = 0x01,
+ SELECTED = 0x02,
+ CURRENT = 0x04,
+ ANCHOR = 0x08
+ };
+
+ int flags;
+
+
+ //geometry
+ QRect rect;
+
+
+
+ //TODO remove
+ bool separator;
+ bool selected;
+ bool current;
+ int bgY; //top of the background
+ int textY; //base line of the text
+};
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class ListWidgetDrawer
+{
+public:
+ ListWidgetDrawer();
+ ~ListWidgetDrawer();
+
+ void readSettings();
+ void loadColors();
+ void drawBackground(QPainter *painter, ListWidgetRow *row);
+ void drawSeparator(QPainter *painter, int m_number_width, ListWidgetRow *row, bool rtl);
+ void drawTrack(QPainter *painter, int m_number_width, ListWidgetRow *row, bool rtl);
+
+private:
+ QColor m_normal, m_current, m_normal_bg, m_selected_bg;
+ Skin *m_skin;
+ QFontMetrics *m_metrics;
+ QFontMetrics *m_extra_metrics;
+ QFont m_font, m_extra_font;
+ bool m_show_anchor;
+ bool m_update;
+};
+
+#endif // LISTWIDGETDRAWER_H
diff --git a/src/plugins/Ui/skinned/skinned.pro b/src/plugins/Ui/skinned/skinned.pro
index f1ab2f846..687121b59 100644
--- a/src/plugins/Ui/skinned/skinned.pro
+++ b/src/plugins/Ui/skinned/skinned.pro
@@ -54,7 +54,8 @@ HEADERS += mainwindow.h \
shortcutdialog.h \
skinnedfactory.h \
skinnedsettings.h \
- hotkeyeditor.h
+ hotkeyeditor.h \
+ listwidgetdrawer.h
SOURCES += mainwindow.cpp \
button.cpp \
display.cpp \
@@ -102,7 +103,8 @@ SOURCES += mainwindow.cpp \
shortcutdialog.cpp \
skinnedfactory.cpp \
skinnedsettings.cpp \
- hotkeyeditor.cpp
+ hotkeyeditor.cpp \
+ listwidgetdrawer.cpp
TEMPLATE = lib
unix:QMAKE_LIBDIR += ../../../../lib