more work on main window
This commit is contained in:
parent
e3ebcff4a5
commit
4306dce221
|
@ -609,3 +609,40 @@ QPixmap game_list_frame::PaintedPixmap(const QPixmap& icon) const
|
|||
// Scale and return our final image
|
||||
return canvas.scaled(m_icon_size * device_pixel_ratio, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation);
|
||||
}
|
||||
void game_list_frame::SetListMode(const bool& is_list)
|
||||
{
|
||||
m_old_layout_is_list = m_is_list_layout;
|
||||
m_is_list_layout = is_list;
|
||||
|
||||
m_gui_settings->SetValue(gui::game_list_listMode, is_list);
|
||||
|
||||
Refresh(true);
|
||||
|
||||
m_central_widget->setCurrentWidget(m_is_list_layout ? m_game_list : m_game_grid);
|
||||
}
|
||||
void game_list_frame::SetSearchText(const QString& text)
|
||||
{
|
||||
m_search_text = text;
|
||||
Refresh();
|
||||
}
|
||||
void game_list_frame::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
QDockWidget::closeEvent(event);
|
||||
Q_EMIT GameListFrameClosed();
|
||||
}
|
||||
|
||||
void game_list_frame::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
if (!m_is_list_layout)
|
||||
{
|
||||
Refresh(false, m_game_grid->selectedItems().count());
|
||||
}
|
||||
QDockWidget::resizeEvent(event);
|
||||
}
|
||||
void game_list_frame::ResizeIcons(const int& slider_pos)
|
||||
{
|
||||
m_icon_size_index = slider_pos;
|
||||
m_icon_size = gui_settings::SizeFromSlider(slider_pos);
|
||||
|
||||
RepaintIcons();
|
||||
}
|
|
@ -37,13 +37,22 @@ public :
|
|||
/** Repaint Gamelist Icons with new background color */
|
||||
void RepaintIcons(const bool& from_settings = false);
|
||||
|
||||
/** Resize Gamelist Icons to size given by slider position */
|
||||
void ResizeIcons(const int& slider_pos);
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetSearchText(const QString& text);
|
||||
void SetListMode(const bool& is_list);
|
||||
private Q_SLOTS:
|
||||
void OnHeaderColumnClicked(int col);
|
||||
void OnRepaintFinished();
|
||||
void OnRefreshFinished();
|
||||
Q_SIGNALS:
|
||||
void GameListFrameClosed();
|
||||
void RequestIconSizeChange(const int& val);
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
private:
|
||||
QPixmap PaintedPixmap(const QPixmap& icon) const;
|
||||
void SortGameList() const;
|
||||
|
@ -75,6 +84,12 @@ private:
|
|||
QFutureWatcher<game_list_item*> m_repaint_watcher;
|
||||
QFutureWatcher<void> m_refresh_watcher;
|
||||
|
||||
// Search
|
||||
QString m_search_text;
|
||||
|
||||
// Icon Size
|
||||
int m_icon_size_index = 0;
|
||||
|
||||
// Icons
|
||||
QSize m_icon_size;
|
||||
QColor m_icon_color;
|
||||
|
|
|
@ -19,4 +19,8 @@ bool gui_settings::GetGamelistColVisibility(int col) const
|
|||
gui_save gui_settings::GetGuiSaveForColumn(int col)
|
||||
{
|
||||
return gui_save{ gui::game_list, "visibility_" + gui::get_game_list_column_name(static_cast<gui::game_list_columns>(col)), true };
|
||||
}
|
||||
QSize gui_settings::SizeFromSlider(int pos)
|
||||
{
|
||||
return gui::game_list_icon_size_min + (gui::game_list_icon_size_max - gui::game_list_icon_size_min) * (1.f * pos / gui::game_list_max_slider_pos);
|
||||
}
|
|
@ -55,6 +55,13 @@ namespace gui
|
|||
|
||||
const int game_list_max_slider_pos = 100;
|
||||
|
||||
inline int get_Index(const QSize& current)
|
||||
{
|
||||
const int size_delta = game_list_icon_size_max.width() - game_list_icon_size_min.width();
|
||||
const int current_delta = current.width() - game_list_icon_size_min.width();
|
||||
return game_list_max_slider_pos * current_delta / size_delta;
|
||||
}
|
||||
|
||||
const QString main_window = "main_window";
|
||||
const QString game_list = "GameList";
|
||||
|
||||
|
@ -65,6 +72,8 @@ namespace gui
|
|||
const gui_save game_list_sortAsc = gui_save(game_list, "sortAsc", true);
|
||||
const gui_save game_list_sortCol = gui_save(game_list, "sortCol", 1);
|
||||
const gui_save game_list_state = gui_save(game_list, "state", QByteArray());
|
||||
const gui_save game_list_iconSize = gui_save(game_list, "iconSize", get_Index(game_list_icon_size_small));
|
||||
const gui_save game_list_iconSizeGrid = gui_save(game_list, "iconSizeGrid", get_Index(game_list_icon_size_small));
|
||||
const gui_save game_list_iconColor = gui_save(game_list, "iconColor", game_list_icon_color);
|
||||
const gui_save game_list_listMode = gui_save(game_list, "listMode", true);
|
||||
const gui_save game_list_textFactor = gui_save(game_list, "textFactor", qreal{ 2.0 });
|
||||
|
@ -86,5 +95,6 @@ public:
|
|||
public Q_SLOTS:
|
||||
void SetGamelistColVisibility(int col, bool val) const;
|
||||
static gui_save GetGuiSaveForColumn(int col);
|
||||
static QSize SizeFromSlider(int pos);
|
||||
};
|
||||
|
||||
|
|
|
@ -28,6 +28,12 @@ bool main_window::Init()
|
|||
|
||||
CreateActions();
|
||||
CreateDockWindows();
|
||||
CreateConnects();
|
||||
|
||||
setMinimumSize(350, minimumSizeHint().height());
|
||||
setWindowTitle(QString::fromStdString("ShadPS4 v0.0.2"));
|
||||
|
||||
ConfigureGuiFromSettings();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -71,3 +77,113 @@ void main_window::CreateDockWindows()
|
|||
}
|
||||
});
|
||||
}
|
||||
void main_window::CreateConnects()
|
||||
{
|
||||
connect(ui->exitAct, &QAction::triggered, this, &QWidget::close);
|
||||
|
||||
connect(ui->showGameListAct, &QAction::triggered, this, [this](bool checked)
|
||||
{
|
||||
checked ? m_game_list_frame->show() : m_game_list_frame->hide();
|
||||
m_gui_settings->SetValue(gui::main_window_gamelist_visible, checked);
|
||||
});
|
||||
connect(ui->refreshGameListAct, &QAction::triggered, this, [this]
|
||||
{
|
||||
m_game_list_frame->Refresh(true);
|
||||
});
|
||||
|
||||
connect(m_icon_size_act_group, &QActionGroup::triggered, this, [this](QAction* act)
|
||||
{
|
||||
static const int index_small = gui::get_Index(gui::game_list_icon_size_small);
|
||||
static const int index_medium = gui::get_Index(gui::game_list_icon_size_medium);
|
||||
|
||||
int index;
|
||||
|
||||
if (act == ui->setIconSizeTinyAct)
|
||||
index = 0;
|
||||
else if (act == ui->setIconSizeSmallAct)
|
||||
index = index_small;
|
||||
else if (act == ui->setIconSizeMediumAct)
|
||||
index = index_medium;
|
||||
else
|
||||
index = gui::game_list_max_slider_pos;
|
||||
|
||||
m_save_slider_pos = true;
|
||||
ResizeIcons(index);
|
||||
});
|
||||
connect(m_game_list_frame, &game_list_frame::RequestIconSizeChange, this, [this](const int& val)
|
||||
{
|
||||
const int idx = ui->sizeSlider->value() + val;
|
||||
m_save_slider_pos = true;
|
||||
ResizeIcons(idx);
|
||||
});
|
||||
|
||||
connect(m_list_mode_act_group, &QActionGroup::triggered, this, [this](QAction* act)
|
||||
{
|
||||
const bool is_list_act = act == ui->setlistModeListAct;
|
||||
if (is_list_act == m_is_list_mode)
|
||||
return;
|
||||
|
||||
const int slider_pos = ui->sizeSlider->sliderPosition();
|
||||
ui->sizeSlider->setSliderPosition(m_other_slider_pos);
|
||||
SetIconSizeActions(m_other_slider_pos);
|
||||
m_other_slider_pos = slider_pos;
|
||||
|
||||
m_is_list_mode = is_list_act;
|
||||
m_game_list_frame->SetListMode(m_is_list_mode);
|
||||
});
|
||||
connect(ui->sizeSlider, &QSlider::valueChanged, this, &main_window::ResizeIcons);
|
||||
connect(ui->sizeSlider, &QSlider::sliderReleased, this, [this]
|
||||
{
|
||||
const int index = ui->sizeSlider->value();
|
||||
m_gui_settings->SetValue(m_is_list_mode ? gui::game_list_iconSize : gui::game_list_iconSizeGrid, index);
|
||||
SetIconSizeActions(index);
|
||||
});
|
||||
connect(ui->sizeSlider, &QSlider::actionTriggered, this, [this](int action)
|
||||
{
|
||||
if (action != QAbstractSlider::SliderNoAction && action != QAbstractSlider::SliderMove)
|
||||
{ // we only want to save on mouseclicks or slider release (the other connect handles this)
|
||||
m_save_slider_pos = true; // actionTriggered happens before the value was changed
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->mw_searchbar, &QLineEdit::textChanged, m_game_list_frame, &game_list_frame::SetSearchText);
|
||||
}
|
||||
|
||||
void main_window::SetIconSizeActions(int idx) const
|
||||
{
|
||||
static const int threshold_tiny = gui::get_Index((gui::game_list_icon_size_small + gui::game_list_icon_size_min) / 2);
|
||||
static const int threshold_small = gui::get_Index((gui::game_list_icon_size_medium + gui::game_list_icon_size_small) / 2);
|
||||
static const int threshold_medium = gui::get_Index((gui::game_list_icon_size_max + gui::game_list_icon_size_medium) / 2);
|
||||
|
||||
if (idx < threshold_tiny)
|
||||
ui->setIconSizeTinyAct->setChecked(true);
|
||||
else if (idx < threshold_small)
|
||||
ui->setIconSizeSmallAct->setChecked(true);
|
||||
else if (idx < threshold_medium)
|
||||
ui->setIconSizeMediumAct->setChecked(true);
|
||||
else
|
||||
ui->setIconSizeLargeAct->setChecked(true);
|
||||
}
|
||||
void main_window::ResizeIcons(int index)
|
||||
{
|
||||
if (ui->sizeSlider->value() != index)
|
||||
{
|
||||
ui->sizeSlider->setSliderPosition(index);
|
||||
return; // ResizeIcons will be triggered again by setSliderPosition, so return here
|
||||
}
|
||||
|
||||
if (m_save_slider_pos)
|
||||
{
|
||||
m_save_slider_pos = false;
|
||||
m_gui_settings->SetValue(m_is_list_mode ? gui::game_list_iconSize : gui::game_list_iconSizeGrid, index);
|
||||
|
||||
// this will also fire when we used the actions, but i didn't want to add another boolean member
|
||||
SetIconSizeActions(index);
|
||||
}
|
||||
|
||||
m_game_list_frame->ResizeIcons(index);
|
||||
}
|
||||
void main_window::ConfigureGuiFromSettings()
|
||||
{
|
||||
|
||||
}
|
|
@ -26,9 +26,14 @@ public:
|
|||
~main_window();
|
||||
bool Init();
|
||||
|
||||
private Q_SLOTS:
|
||||
void ConfigureGuiFromSettings();
|
||||
void SetIconSizeActions(int idx) const;
|
||||
void ResizeIcons(int index);
|
||||
private:
|
||||
void CreateActions();
|
||||
void CreateDockWindows();
|
||||
void CreateConnects();
|
||||
|
||||
QActionGroup* m_icon_size_act_group = nullptr;
|
||||
QActionGroup* m_list_mode_act_group = nullptr;
|
||||
|
|
Loading…
Reference in New Issue