Skip to content

Commit

Permalink
FileMenu now dynamically determines the required size for the buttons
Browse files Browse the repository at this point in the history
This makes it smaller than it was before which makes the preference menus *just* usable on the minimumwindow size
I did move the treshold spinbox down a bit to make it fit
  • Loading branch information
JorisGoosen committed Nov 15, 2023
1 parent 4ad8331 commit ff81cb2
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 65 deletions.
72 changes: 34 additions & 38 deletions Desktop/components/JASP/Widgets/FileMenu/FileMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ FocusScope

property int actionButtionHeight: 35 * preferencesModel.uiScale
property int resourceButtonHeight: 1.5 * actionButtionHeight
property int nbColumns: 1 + (resourceRepeaterId.count > 0 ? 1 : 0 )
property int colWidths: 190


Connections
Expand All @@ -54,7 +52,7 @@ FocusScope
property real desiredX: !fileMenuModel.visible ? -(resourceScreen.otherColumnsWidth + resourceScreen.width) : 0

x: desiredX
width: (fileMenu.nbColumns * fileMenu.colWidths * preferencesModel.uiScale) + (resourceScreen.aButtonVisible ? resourceScreen.width : 0)
width: (actionMenu.width + resourceMenu.width ) + (resourceScreen.aButtonVisible ? resourceScreen.width : 0)
height: fileMenu.height

Behavior on x
Expand Down Expand Up @@ -82,7 +80,7 @@ FocusScope
{
id: actionMenu
anchors.left: parent.left
width: fileMenu.colWidths * preferencesModel.uiScale
width: fileMenuModel.actionButtons.width + jaspTheme.subMenuIconHeight + jaspTheme.generalAnchorMargin * 5
height: parent.height
z: 4
contentWidth: width
Expand All @@ -95,15 +93,14 @@ FocusScope

Column
{
id: fileAction
spacing: 4
width: parent.width - jaspTheme.generalAnchorMargin
id: fileAction
spacing: jaspTheme.menuSpacing
width: parent.width

anchors
{
top: parent.top
topMargin: 5
horizontalCenter: parent.horizontalCenter
fill: parent
margins: jaspTheme.generalAnchorMargin
}

Repeater
Expand All @@ -114,7 +111,7 @@ FocusScope
Item
{
id: itemActionMenu
width: parent.width - (6 * preferencesModel.uiScale)
width: parent.width
anchors.left: parent.left
height: actionButtionHeight + actionToolSeperator.height
enabled: enabledRole
Expand All @@ -123,18 +120,12 @@ FocusScope
{
id: actionMenuButton
hasSubMenu: hasSubMenuRole
width: itemActionMenu.width
width: parent.width
height: actionButtionHeight
text: nameRole
selected: selectedRole
focus: selectedRole

anchors
{
leftMargin: 3 * preferencesModel.uiScale
left: itemActionMenu.left
}

ALTNavigation.enabled: true
ALTNavigation.x: width * 0.9
ALTNavigation.onTagMatch: { clicked(); }
Expand Down Expand Up @@ -165,10 +156,15 @@ FocusScope
ToolSeparator
{
id: actionToolSeperator
anchors.top: actionMenuButton.bottom
width: actionMenuButton.width
anchors.topMargin: (showToolSeperator(typeRole) ? 3 : 0) * preferencesModel.uiScale
anchors.left: actionMenuButton.left
anchors
{
top: actionMenuButton.bottom
topMargin: (showToolSeperator(typeRole) ? 3 : 0) * preferencesModel.uiScale
left: parent.left
right: parent.right
leftMargin: -jaspTheme.generalAnchorMargin
rightMargin: -jaspTheme.generalAnchorMargin
}

orientation: Qt.Horizontal
visible: showToolSeperator(typeRole)
Expand All @@ -192,10 +188,10 @@ FocusScope
{
id: resourceMenu

width: fileMenu.colWidths * preferencesModel.uiScale
width: !hasButtons ? 0 : fileMenuModel.resourceButtons.width + jaspTheme.subMenuIconHeight + jaspTheme.generalAnchorMargin * 5
height: parent.height
anchors.left: actionMenu.right
anchors.leftMargin: hasButtons ? 0 : - fileMenu.colWidths * preferencesModel.uiScale
anchors.leftMargin: hasButtons ? 0 : -width
z: 2
contentWidth: width
contentHeight: resourceLocation.implicitHeight
Expand All @@ -204,6 +200,12 @@ FocusScope

Keys.onLeftPressed: actionMenu.forceActiveFocus();
Keys.onEscapePressed: actionMenu.forceActiveFocus();



property bool hasButtons: resourceRepeaterId.count > 0

visible: hasButtons

Behavior on anchors.leftMargin
{
Expand All @@ -217,20 +219,16 @@ FocusScope
}
}



property bool hasButtons: resourceRepeaterId.count > 0

visible: hasButtons

Column
{
id: resourceLocation

anchors.top: parent.top
anchors.topMargin: 5 * preferencesModel.uiScale
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - jaspTheme.generalAnchorMargin
anchors
{
fill: parent
margins: jaspTheme.generalAnchorMargin
}


spacing: 6 * preferencesModel.uiScale

Expand All @@ -243,10 +241,8 @@ FocusScope
{

id: itemResourceMenu
width: parent.width - (6 * preferencesModel.uiScale)
width: parent.width
height: resourceButtonHeight
anchors.leftMargin: 3 * preferencesModel.uiScale
anchors.left: parent.left
enabled: enabledRole

MenuButton
Expand Down Expand Up @@ -310,7 +306,7 @@ FocusScope

Rectangle
{
property real otherColumnsWidth: fileMenu.colWidths * fileMenu.nbColumns * preferencesModel.uiScale
property real otherColumnsWidth: actionMenu.width + resourceMenu.width
property bool aButtonVisible: resourceRepeaterId.count > 0 && fileMenuModel.resourceButtons.currentQML !== ''

property real desiredWidth: Math.min(mainWindowRoot.width - otherColumnsWidth, 600 * preferencesModel.uiScale)
Expand Down
12 changes: 6 additions & 6 deletions Desktop/components/JASP/Widgets/FileMenu/PrefsData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ ScrollView

Item //Scale threshold
{
height: customThreshold.height
width: customThreshold.width + thresholdScale.width
height: customThreshold.height + thresholdScale.height
width: customThreshold.width

CheckBox
{
id: customThreshold
label: qsTr("Import threshold between Categorical or Scale")
label: qsTr("Import threshold between Categorical or Scale") + ":"
checked: preferencesModel.customThresholdScale
onCheckedChanged: preferencesModel.customThresholdScale = checked
ToolTip.delay: 500
Expand All @@ -161,9 +161,9 @@ ScrollView

anchors
{
left: customThreshold.right
leftMargin: jaspTheme.generalAnchorMargin
verticalCenter: parent.verticalCenter
top: customThreshold.bottom
left: customThreshold.left
leftMargin: jaspTheme.subOptionOffset
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ void MainWindow::makeConnections()
connect(_preferences, &PreferencesModel::developerModeChanged, _analyses, &Analyses::refreshAllAnalyses );
connect(_preferences, &PreferencesModel::currentJaspThemeChanged, this, &MainWindow::setCurrentJaspTheme );
connect(_preferences, &PreferencesModel::currentThemeNameChanged, _resultsJsInterface, &ResultsJsInterface::setThemeCss );
connect(_preferences, &PreferencesModel::currentThemeNameChanged, _fileMenu, &FileMenu::refresh );
connect(_preferences, &PreferencesModel::uiScaleChanged, _fileMenu, &FileMenu::refresh );
connect(_preferences, &PreferencesModel::resultFontChanged, _resultsJsInterface, &ResultsJsInterface::setFontFamily );
connect(_preferences, &PreferencesModel::resultFontChanged, _engineSync, &EngineSync::refreshAllPlots );
connect(_preferences, &PreferencesModel::restartAllEngines, _engineSync, &EngineSync::haveYouTriedTurningItOffAndOnAgain );
Expand Down Expand Up @@ -647,12 +649,12 @@ void MainWindow::loadQML()
connect(_preferences, &PreferencesModel::maxFlickVelocityChanged, keyval.second, &JaspTheme::maxFlickVeloHandler );
}


_fileMenu->refresh(); //Now that the theme is loaded we can determine the proper width for the buttons in the filemenu

Log::log() << "Loading HelpWindow" << std::endl; _qml->load(QUrl("qrc:///components/JASP/Widgets/HelpWindow.qml"));
Log::log() << "Loading AboutWindow" << std::endl; _qml->load(QUrl("qrc:///components/JASP/Widgets/AboutWindow.qml"));
Log::log() << "Loading ContactWindow" << std::endl; _qml->load(QUrl("qrc:///components/JASP/Widgets/ContactWindow.qml"));
Log::log() << "Loading CommunityWindow" << std::endl; _qml->load(QUrl("qrc:///components/JASP/Widgets/CommunityWindow.qml"));
Log::log() << "Loading CommunityWindow" << std::endl; _qml->load(QUrl("qrc:///components/JASP/Widgets/CommunityWindow.qml"));
Log::log() << "Loading MainWindow" << std::endl; _qml->load(QUrl("qrc:///components/JASP/Widgets/MainWindow.qml"));


Expand Down
40 changes: 33 additions & 7 deletions Desktop/widgets/filemenu/actionbuttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#include <QObject>
#include <QtQml>
#include "log.h"
#include "jasptheme.h"

ActionButtons::ActionButtons(QObject *parent) : QAbstractListModel (parent),
_data()

ActionButtons::ActionButtons(QObject *parent) : QAbstractListModel (parent)
{
loadButtonData(_data);
loadButtonData();

for(size_t i=0; i<_data.size(); i++)
_opToIndex[_data[i].operation] = i;
Expand All @@ -17,9 +16,11 @@ ActionButtons::ActionButtons(QObject *parent) : QAbstractListModel (parent),
connect(this, &ActionButtons::buttonClicked, this, &ActionButtons::setSelectedAction);
}

void ActionButtons::loadButtonData(std::vector<ActionButtons::DataRow> &data)
void ActionButtons::loadButtonData()
{
_data =
_width = 0;

_data =
{
{FileOperation::Open, tr("Open"), true, {ResourceButtons::Computer, ResourceButtons::OSF, ResourceButtons::Database, ResourceButtons::RecentFiles, ResourceButtons::DataLibrary } },
{FileOperation::Save, tr("Save"), false, {} },
Expand All @@ -33,6 +34,18 @@ void ActionButtons::loadButtonData(std::vector<ActionButtons::DataRow> &data)
{FileOperation::Community, tr("Community"), true, {} },
{FileOperation::About, tr("About"), true, {} }
};


if(JaspTheme::currentTheme())
{

QFontMetricsF ribbonMetrics(JaspTheme::currentTheme()->fontRibbon());

for(const auto & action : _data)
_width = std::max(_width, int(ribbonMetrics.boundingRect(action.name).width()));

emit widthChanged();
}
}

QVariant ActionButtons::data(const QModelIndex &index, int role) const
Expand Down Expand Up @@ -113,7 +126,7 @@ void ActionButtons::refresh()

std::vector<DataRow> savedata = _data;

loadButtonData(_data);
loadButtonData();

for(int i=0 ; i < savedata.size() ; i++)
_data[i].enabled = savedata[i].enabled;
Expand Down Expand Up @@ -158,3 +171,16 @@ void ActionButtons::selectButtonDown()
}
}
}

int ActionButtons::width() const
{
return _width;
}

void ActionButtons::setWidth(int newWidth)
{
if (_width == newWidth)
return;
_width = newWidth;
emit widthChanged();
}
16 changes: 11 additions & 5 deletions Desktop/widgets/filemenu/actionbuttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class ActionButtons : public QAbstractListModel
{
Q_OBJECT

Q_PROPERTY(FileOperation selectedAction READ selectedAction WRITE setSelectedAction NOTIFY selectedActionChanged)
Q_PROPERTY(FileOperation selectedAction READ selectedAction WRITE setSelectedAction NOTIFY selectedActionChanged)
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged )

public:
enum FileOperation {None = 0, Open, Save, SaveAs, ExportResults, ExportData, SyncData, Close, Preferences, Contact, Community, About};
Expand All @@ -34,22 +35,27 @@ class ActionButtons : public QAbstractListModel

std::set<ResourceButtons::ButtonType> resourceButtonsForButton(FileOperation button);
void refresh();


int width() const;
void setWidth(int newWidth);

signals:
void selectedActionChanged( ActionButtons::FileOperation selectedAction);
void buttonClicked( ActionButtons::FileOperation selectedAction);


void widthChanged();

public slots:
void setEnabled( ActionButtons::FileOperation operation, bool enabledState);
void setSelectedAction( ActionButtons::FileOperation selectedAction);


private:
void loadButtonData(std::vector<DataRow> & data);
void loadButtonData();

std::vector<DataRow> _data;
std::map<FileOperation, size_t> _opToIndex;
FileOperation _selected = None;
int _width = 0;
};

#endif // ACTIONBUTTONS_H
Loading

0 comments on commit ff81cb2

Please sign in to comment.