Enable customizing the save statistics time interval
[qBittorrent.git] / src / gui / properties / piecesbar.h
blob3811ae4711d2b4c40342cbbfd60aa64ec85607bd
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2016 Eugene Shalygin
5 * Copyright (C) 2006 Christophe Dumez
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
31 #pragma once
33 #include <QColor>
34 #include <QImage>
35 #include <QWidget>
37 class QHelpEvent;
39 namespace BitTorrent
41 class Torrent;
44 class PiecesBar : public QWidget
46 Q_OBJECT
47 Q_DISABLE_COPY_MOVE(PiecesBar)
49 using base = QWidget;
51 public:
52 explicit PiecesBar(QWidget *parent = nullptr);
54 void setTorrent(const BitTorrent::Torrent *torrent);
56 virtual void clear();
58 protected:
59 bool event(QEvent *e) override;
60 void enterEvent(QEnterEvent *e) override;
61 void leaveEvent(QEvent *e) override;
62 void mouseMoveEvent(QMouseEvent *e) override;
63 void paintEvent(QPaintEvent *e) override;
65 virtual void updateColors();
66 void redraw();
68 QColor backgroundColor() const;
69 QColor borderColor() const;
70 QColor pieceColor() const;
71 QColor highlightedPieceColor() const;
72 QColor colorBoxBorderColor() const;
74 const QList<QRgb> &pieceColors() const;
76 // mix two colors by light model, ratio <0, 1>
77 static QRgb mixTwoColors(QRgb rgb1, QRgb rgb2, float ratio);
79 static constexpr int borderWidth = 1;
81 private:
82 void showToolTip(const QHelpEvent*);
83 void highlightFile(int imagePos);
85 virtual QString simpleToolTipText() const = 0;
86 virtual QImage renderImage() = 0;
88 void updateColorsImpl();
90 const BitTorrent::Torrent *m_torrent = nullptr;
91 QImage m_image;
92 // buffered 256 levels gradient from bg_color to piece_color
93 QList<QRgb> m_pieceColors;
94 bool m_hovered = false;
95 QRect m_highlightedRegion; // part of the bar can be highlighted; this rectangle is in the same frame as m_image