1 /***************************************************************************
2  *   Copyright (C) 2015-2021 by Ilya Kotov                                 *
3  *   forkotov02@ya.ru                                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20 
21 #ifndef LISTWIDGETDRAWER_H
22 #define LISTWIDGETDRAWER_H
23 
24 #include <QString>
25 #include <QStringList>
26 #include <QColor>
27 #include <QRect>
28 #include <QFontMetrics>
29 
30 
31 class QPainter;
32 class PlayListHeaderModel;
33 
34 struct ListWidgetRow
35 {
ListWidgetRowListWidgetRow36     ListWidgetRow()
37     {
38         flags = NO_FLAGS;
39         numberColumnWidth = 0;
40         lengthColumnWidth = 0;
41         trackStateColumn = -1;
42         autoResize = false;
43         number = 0;
44     }
45     QStringList titles;
46     QList<int> sizes;
47     QList<int> alignment;
48     QString length;
49     QString extraString;
50     int number;
51     int numberColumnWidth;
52     int lengthColumnWidth;
53     int trackStateColumn;
54     enum
55     {
56         NO_FLAGS = 0x00,
57         GROUP = 0x01,
58         SELECTED = 0x02,
59         CURRENT = 0x04,
60         ANCHOR = 0x08
61     };
62 
63     enum
64     {
65         ALIGN_LEFT = 0,
66         ALIGN_CENTER,
67         ALIGN_RIGHT,
68     };
69 
70     int flags;
71     QRect rect; //geometry
72     bool autoResize;
73 };
74 
75 /**
76    @author Ilya Kotov <forkotov02@ya.ru>
77 */
78 class ListWidgetDrawer
79 {
80 public:
81     ListWidgetDrawer();
82     ~ListWidgetDrawer();
83 
84     void readSettings();
85     void loadSystemColors();
86     int rowHeight() const;
87     int numberWidth() const;
88     void calculateNumberWidth(int count);
89     void setSingleColumnMode(int enabled);
90     void prepareRow(ListWidgetRow *row);
91     void fillBackground(QPainter *painter, int width, int height);
92     void drawBackground(QPainter *painter, ListWidgetRow *row, int index);
93     void drawSeparator(QPainter *painter, ListWidgetRow *row, bool rtl);
94     void drawTrack(QPainter *painter, ListWidgetRow *row, bool rtl);
95     void drawDropLine(QPainter *painter, int row_number, int width, int header_height);
96 
97 private:
98     QColor m_normal, m_current, m_normal_bg, m_selected_bg, m_alternate, m_highlighted, m_splitter;
99     QColor m_group_bg, m_group_alt_bg, m_group_text, m_current_bg, m_current_alt_bg;
100     QFontMetrics *m_metrics = nullptr;
101     QFontMetrics *m_extra_metrics = nullptr;
102     QFontMetrics *m_bold_metrics = nullptr;
103     PlayListHeaderModel *m_header_model;
104     QFont m_font, m_extra_font;
105     bool m_update = false;
106     bool m_show_number = false;
107     bool m_show_anchor = false;
108     bool m_align_numbres = false;
109     bool m_show_lengths = false;
110     bool m_use_system_colors = false;
111     bool m_single_column = true;
112     bool m_show_splitters = true;
113     int m_padding = 0;
114     int m_number_width = 0;
115     int m_row_height = 0;
116 };
117 
118 #endif // LISTWIDGETDRAWER_H
119