Fix minor code issues

This commit is contained in:
Jonas Kvinge
2019-09-15 20:27:32 +02:00
parent 83e10aac27
commit 2d67279180
147 changed files with 644 additions and 329 deletions

View File

@@ -58,60 +58,67 @@ void AutoExpandingTreeView::reset() {
}
}
void AutoExpandingTreeView::RecursivelyExpand(const QModelIndex &index) {
int rows = model()->rowCount(index);
RecursivelyExpand(index, &rows);
void AutoExpandingTreeView::RecursivelyExpand(const QModelIndex &idx) {
int rows = model()->rowCount(idx);
RecursivelyExpand(idx, &rows);
}
bool AutoExpandingTreeView::RecursivelyExpand(const QModelIndex &index, int *count) {
if (!CanRecursivelyExpand(index))
bool AutoExpandingTreeView::RecursivelyExpand(const QModelIndex &idx, int *count) {
if (!CanRecursivelyExpand(idx))
return true;
if (model()->canFetchMore(index))
model()->fetchMore(index);
if (model()->canFetchMore(idx))
model()->fetchMore(idx);
int children = model()->rowCount(index);
int children = model()->rowCount(idx);
if (*count + children > kRowsToShow)
return false;
expand(index);
expand(idx);
*count += children;
for (int i = 0 ; i < children ; ++i) {
if (!RecursivelyExpand(model()->index(i, 0, index), count))
if (!RecursivelyExpand(model()->index(i, 0, idx), count))
return false;
}
return true;
}
void AutoExpandingTreeView::ItemExpanded(const QModelIndex &index) {
if (model()->rowCount(index) == 1 && auto_open_)
expand(model()->index(0, 0, index));
void AutoExpandingTreeView::ItemExpanded(const QModelIndex &idx) {
if (model()->rowCount(idx) == 1 && auto_open_)
expand(model()->index(0, 0, idx));
}
void AutoExpandingTreeView::ItemClicked(const QModelIndex &index) {
void AutoExpandingTreeView::ItemClicked(const QModelIndex &idx) {
if (ignore_next_click_) {
ignore_next_click_ = false;
return;
}
setExpanded(index, !isExpanded(index));
setExpanded(idx, !isExpanded(idx));
}
void AutoExpandingTreeView::ItemDoubleClicked(const QModelIndex &index) {
void AutoExpandingTreeView::ItemDoubleClicked(const QModelIndex &idx) {
ignore_next_click_ = true;
if (add_on_double_click_) {
QMimeData *data = model()->mimeData(QModelIndexList() << index);
QMimeData *data = model()->mimeData(QModelIndexList() << idx);
if (MimeData *mime_data = qobject_cast<MimeData*>(data)) {
mime_data->from_doubleclick_ = true;
}
emit AddToPlaylistSignal(data);
}
}
void AutoExpandingTreeView::mousePressEvent(QMouseEvent *event) {
if (event->modifiers() != Qt::NoModifier) {
ignore_next_click_ = true;
}
@@ -126,23 +133,27 @@ void AutoExpandingTreeView::mousePressEvent(QMouseEvent *event) {
}
emit AddToPlaylistSignal(data);
}
}
void AutoExpandingTreeView::mouseDoubleClickEvent(QMouseEvent *event) {
State p_state = state();
QModelIndex index = indexAt(event->pos());
QModelIndex idx = indexAt(event->pos());
QTreeView::mouseDoubleClickEvent(event);
// If the p_state was the "AnimatingState", then the base class's
// "mouseDoubleClickEvent" method just did nothing, hence the "doubleClicked" signal is not emitted. So let's do it ourselves.
if (index.isValid() && p_state == AnimatingState) {
emit doubleClicked(index);
if (idx.isValid() && p_state == AnimatingState) {
emit doubleClicked(idx);
}
}
void AutoExpandingTreeView::keyPressEvent(QKeyEvent *e) {
QModelIndex index = currentIndex();
QModelIndex idx = currentIndex();
switch (e->key()) {
case Qt::Key_Enter:
@@ -160,8 +171,8 @@ void AutoExpandingTreeView::keyPressEvent(QKeyEvent *e) {
case Qt::Key_Left:
// Set focus on the root of the current branch
if (index.isValid() && index.parent() != rootIndex() && (!isExpanded(index) || model()->rowCount(index) == 0)) {
setCurrentIndex(index.parent());
if (idx.isValid() && idx.parent() != rootIndex() && (!isExpanded(idx) || model()->rowCount(idx) == 0)) {
setCurrentIndex(idx.parent());
setFocus();
e->accept();
}
@@ -169,6 +180,7 @@ void AutoExpandingTreeView::keyPressEvent(QKeyEvent *e) {
}
QTreeView::keyPressEvent(e);
}
void AutoExpandingTreeView::UpAndFocus() {

View File

@@ -47,7 +47,7 @@ class AutoExpandingTreeView : public QTreeView {
void SetAddOnDoubleClick(bool v) { add_on_double_click_ = v; }
public slots:
void RecursivelyExpand(const QModelIndex &index);
void RecursivelyExpand(const QModelIndex &idx);
void UpAndFocus();
void DownAndFocus();
@@ -64,21 +64,20 @@ protected:
void mouseDoubleClickEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
virtual bool CanRecursivelyExpand(const QModelIndex &index) const { return true; }
virtual bool CanRecursivelyExpand(const QModelIndex &idx) const { Q_UNUSED(idx); return true; }
private slots:
void ItemExpanded(const QModelIndex &index);
void ItemClicked(const QModelIndex &index);
void ItemDoubleClicked(const QModelIndex &index);
void ItemExpanded(const QModelIndex &idx);
void ItemClicked(const QModelIndex &idx);
void ItemDoubleClicked(const QModelIndex &idx);
private:
bool RecursivelyExpand(const QModelIndex &index, int *count);
bool RecursivelyExpand(const QModelIndex &idx, int *count);
private:
bool auto_open_;
bool expand_on_reset_;
bool add_on_double_click_;
bool ignore_next_click_;
};

View File

@@ -103,6 +103,7 @@ class FancyTabBar: public QTabBar {
}
void leaveEvent(QEvent *event) {
Q_UNUSED(event);
mouseHoverTabIndex = -1;
update();
}

View File

@@ -57,6 +57,8 @@ QSize FavoriteWidget::sizeHint() const {
void FavoriteWidget::paintEvent(QPaintEvent *e) {
Q_UNUSED(e);
QStylePainter p(this);
if (favorite_) {
@@ -69,7 +71,11 @@ void FavoriteWidget::paintEvent(QPaintEvent *e) {
}
void FavoriteWidget::mouseReleaseEvent(QMouseEvent *e) {
Q_UNUSED(e);
favorite_ = !favorite_;
update();
emit FavoriteStateChanged(tab_index_, favorite_);
}

View File

@@ -57,7 +57,7 @@ class GroupedIconView : public QListView {
Q_PROPERTY(int item_indent READ item_indent WRITE set_item_indent)
// The text of each group's header. Must contain "%1".
Q_PROPERTY(QString header_text READ header_text WRITE set_header_text);
Q_PROPERTY(QString header_text READ header_text WRITE set_header_text)
public:
GroupedIconView(QWidget *parent = nullptr);

View File

@@ -104,10 +104,11 @@ protected:
class LineEdit : public QLineEdit, public ExtendedEditor {
Q_OBJECT
Q_PROPERTY(QString hint READ hint WRITE set_hint);
Q_PROPERTY(qreal font_point_size READ font_point_size WRITE set_font_point_size);
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button);
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button);
Q_PROPERTY(QString hint READ hint WRITE set_hint)
Q_PROPERTY(qreal font_point_size READ font_point_size WRITE set_font_point_size)
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button)
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button)
public:
LineEdit(QWidget *parent = nullptr);
@@ -135,9 +136,9 @@ signals:
class TextEdit : public QPlainTextEdit, public ExtendedEditor {
Q_OBJECT
Q_PROPERTY(QString hint READ hint WRITE set_hint);
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button);
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button);
Q_PROPERTY(QString hint READ hint WRITE set_hint)
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button)
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button)
public:
TextEdit(QWidget *parent = nullptr);
@@ -158,9 +159,9 @@ signals:
class SpinBox : public QSpinBox, public ExtendedEditor {
Q_OBJECT
Q_PROPERTY(QString hint READ hint WRITE set_hint);
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button);
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button);
Q_PROPERTY(QString hint READ hint WRITE set_hint)
Q_PROPERTY(bool has_clear_button READ has_clear_button WRITE set_clear_button)
Q_PROPERTY(bool has_reset_button READ has_reset_button WRITE set_reset_button)
public:
SpinBox(QWidget *parent = nullptr);

View File

@@ -102,6 +102,7 @@ QDBusArgument &operator<<(QDBusArgument &arg, const QImage &image) {
}
const QDBusArgument &operator>>(const QDBusArgument &arg, QImage &image) {
Q_UNUSED(image);
// This is needed to link but shouldn't be called.
Q_ASSERT(0);
return arg;

View File

@@ -271,6 +271,8 @@ void PlayingWidget::SongChanged(const Song &song) {
void PlayingWidget::AlbumCoverLoaded(const Song &song, const QUrl &cover_url, const QImage &image) {
Q_UNUSED(cover_url);
if (!playing_ || song != song_playing_ || (timeline_fade_->state() == QTimeLine::Running && image == image_original_)) return;
active_ = true;
@@ -389,6 +391,8 @@ void PlayingWidget::UpdateDetailsText() {
void PlayingWidget::paintEvent(QPaintEvent *e) {
Q_UNUSED(e);
QPainter p(this);
DrawContents(&p);
@@ -398,6 +402,7 @@ void PlayingWidget::paintEvent(QPaintEvent *e) {
p.setOpacity(pixmap_previous_track_opacity_);
p.drawPixmap(0, 0, pixmap_previous_track_);
}
}
void PlayingWidget::DrawContents(QPainter *p) {

View File

@@ -9,8 +9,8 @@ class QSearchFieldPrivate;
class QSearchField : public QWidget {
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true);
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText);
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
public:
explicit QSearchField(QWidget *parent);

View File

@@ -27,11 +27,10 @@
#include "renametablineedit.h"
RenameTabLineEdit::RenameTabLineEdit(QWidget *parent) :
QLineEdit(parent)
{
}
QLineEdit(parent) {}
void RenameTabLineEdit::keyPressEvent (QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
e->accept();
emit EditingCanceled();
@@ -39,11 +38,16 @@ void RenameTabLineEdit::keyPressEvent (QKeyEvent *e) {
else {
QLineEdit::keyPressEvent(e);
}
}
void RenameTabLineEdit::focusOutEvent(QFocusEvent *e) {
Q_UNUSED(e);
//if the user hasn't explicitly accepted, discard the value
emit EditingCanceled();
//we don't call the default event since it will trigger editingFished()
}

View File

@@ -31,8 +31,9 @@ class QMouseEvent;
class StickySlider : public QSlider {
Q_OBJECT
Q_PROPERTY(int sticky_center READ sticky_center WRITE set_sticky_center);
Q_PROPERTY(int sticky_threshold READ sticky_threshold WRITE set_sticky_threshold);
Q_PROPERTY(int sticky_center READ sticky_center WRITE set_sticky_center)
Q_PROPERTY(int sticky_threshold READ sticky_threshold WRITE set_sticky_threshold)
public:
StickySlider(QWidget* parent = nullptr);