2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016 Eugene Shalygin
4 * Copyright (C) 2006 Christophe Dumez
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
43 class PiecesBar
: public QWidget
46 Q_DISABLE_COPY_MOVE(PiecesBar
)
51 explicit PiecesBar(QWidget
*parent
= nullptr);
53 void setTorrent(const BitTorrent::Torrent
*torrent
);
58 virtual bool event(QEvent
*e
) override
;
62 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
63 void enterEvent(QEnterEvent
*e
) override
;
65 void enterEvent(QEvent
*e
) override
;
67 void leaveEvent(QEvent
*e
) override
;
68 void mouseMoveEvent(QMouseEvent
*e
) override
;
70 void paintEvent(QPaintEvent
*e
) override
;
71 void requestImageUpdate();
73 QColor
backgroundColor() const;
74 QColor
borderColor() const;
75 QColor
pieceColor() const;
76 QColor
colorBoxBorderColor() const;
77 const QVector
<QRgb
> &pieceColors() const;
79 // mix two colors by light model, ratio <0, 1>
80 static QRgb
mixTwoColors(QRgb rgb1
, QRgb rgb2
, float ratio
);
82 static constexpr int borderWidth
= 1;
85 void showToolTip(const QHelpEvent
*);
86 void highlightFile(int imagePos
);
88 virtual QString
simpleToolTipText() const = 0;
90 // draw new image to replace the actual image
91 // returns true if image was successfully updated
92 virtual bool updateImage(QImage
&image
) = 0;
93 void updatePieceColors();
95 const BitTorrent::Torrent
*m_torrent
= nullptr;
97 // buffered 256 levels gradient from bg_color to piece_color
98 QVector
<QRgb
> m_pieceColors
;
99 bool m_hovered
= false;
100 QRect m_highlightedRegion
; // part of the bar can be highlighted; this rectangle is in the same frame as m_image