Skip to content

Commit

Permalink
fix: optimize theme panel popup.
Browse files Browse the repository at this point in the history
Change-Id: Iebfc90b03bb14a0cc1882bef9387a36c8f5ce82a
  • Loading branch information
rekols committed Dec 1, 2018
1 parent a8ffa9f commit ce01f2f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/themewidgets/themelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,10 @@ QVariant ThemeListModel::data(const QModelIndex &index, int role) const
switch (role) {
case ThemeName:
return name;

case ThemePath:
return m_themes.at(r).second;

return path;
case FrameNormalColor:
return m_frameNormalColor;

case FrameSelectedColor:
return m_frameSelectedColor;
}
Expand Down
18 changes: 11 additions & 7 deletions src/themewidgets/themepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ThemePanel::ThemePanel(QWidget *parent)
layout->setMargin(0);
layout->setSpacing(0);

setFixedWidth(250);

QWidget::hide();
connect(m_themeView, &ThemeListView::focusOut, this, &ThemePanel::hide);
connect(m_themeView, &ThemeListView::themeChanged, this, &ThemePanel::themeChanged);
Expand Down Expand Up @@ -89,26 +91,28 @@ void ThemePanel::popup()
m_themeView->setFocus();

QRect rect = geometry();
QRect parentRect = parentWidget()->topLevelWidget()->geometry();
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(250);
animation->setEasingCurve(QEasingCurve::InOutCubic);
animation->setStartValue(QRect(rect.x(), rect.y(), 0, rect.height()));
animation->setEndValue(QRect(rect.x(), rect.y(), 250, rect.height()));
animation->setEasingCurve(QEasingCurve::OutQuad);
animation->setStartValue(QRect(parentRect.width(), rect.y(), rect.width(), rect.height()));
animation->setEndValue(QRect(parentRect.width() - rect.width(), rect.y(), rect.width(), rect.height()));
animation->start();

connect(animation, &QPropertyAnimation::valueChanged, [=] { m_themeView->adjustScrollbarMargins(); });
connect(animation, &QPropertyAnimation::finished, this, &ThemePanel::popupFinished);
connect(animation, &QPropertyAnimation::finished, animation, &QPropertyAnimation::deleteLater);
}

void ThemePanel::hide()
{
QRect rect = geometry();
QRect parentRect = parentWidget()->topLevelWidget()->geometry();
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(250);
animation->setEasingCurve(QEasingCurve::InOutCubic);
animation->setStartValue(QRect(rect.x(), rect.y(), 250, rect.height()));
animation->setEndValue(QRect(rect.x(), rect.y(), 0, rect.height()));
animation->setEasingCurve(QEasingCurve::OutQuad);
animation->setStartValue(QRect(parentRect.width() - rect.width(), rect.y(), rect.width(), rect.height()));
animation->setEndValue(QRect(parentRect.width(), rect.y(), rect.width(), rect.height()));

animation->start();

connect(animation, &QPropertyAnimation::finished, [=] { QWidget::hide(); });
Expand Down
1 change: 0 additions & 1 deletion src/themewidgets/themepanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ThemePanel : public QWidget

signals:
void themeChanged(const QString &path);
void popupFinished();

protected:
void paintEvent(QPaintEvent *);
Expand Down
9 changes: 7 additions & 2 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ void Window::initTitlebar()
connect(saveAsAction, &QAction::triggered, this, &Window::saveAsFile);
connect(printAction, &QAction::triggered, this, &Window::popupPrintDialog);
connect(settingAction, &QAction::triggered, this, &Window::popupSettingsDialog);
connect(switchThemeAction, &QAction::triggered, m_themePanel, &ThemePanel::popup);
connect(m_themePanel, &ThemePanel::popupFinished, [=] { m_themePanel->setSelectionTheme(m_themePath); });
connect(switchThemeAction, &QAction::triggered, this, &Window::popupThemePanel);
}

int Window::getTabIndex(const QString &file)
Expand Down Expand Up @@ -757,6 +756,12 @@ void Window::popupPrintDialog()
preview.exec();
}

void Window::popupThemePanel()
{
m_themePanel->setSelectionTheme(m_themePath);
m_themePanel->popup();
}

void Window::toggleFullscreen()
{
if (isFullScreen()) {
Expand Down
1 change: 1 addition & 0 deletions src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Window : public DMainWindow
void popupJumpLineBar();
void popupSettingsDialog();
void popupPrintDialog();
void popupThemePanel();

void toggleFullscreen();

Expand Down

0 comments on commit ce01f2f

Please sign in to comment.