Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
9d969f1f
Commit
9d969f1f
authored
May 20, 2013
by
Bryant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The style changing UI now works somewhat. Doesn't interact with QSettings yet.
parent
ac2522d2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
171 deletions
+137
-171
MainWindow.cc
src/ui/MainWindow.cc
+22
-33
MainWindow.h
src/ui/MainWindow.h
+8
-8
QGCSettingsWidget.cc
src/ui/QGCSettingsWidget.cc
+87
-59
QGCSettingsWidget.h
src/ui/QGCSettingsWidget.h
+7
-4
QGCSettingsWidget.ui
src/ui/QGCSettingsWidget.ui
+13
-67
No files found.
src/ui/MainWindow.cc
View file @
9d969f1f
...
...
@@ -68,9 +68,12 @@ This file is part of the QGROUNDCONTROL project
#include "PxQuadMAV.h"
#include "SlugsMAV.h"
#include "LogCompressor.h"
// Set up some constants
const
QString
MainWindow
::
defaultDarkStyle
=
":files/styles/style-dark.css"
;
const
QString
MainWindow
::
defaultLightStyle
=
":files/styles/style-light.css"
;
MainWindow
*
MainWindow
::
instance
(
QSplashScreen
*
screen
)
{
static
MainWindow
*
_instance
=
0
;
...
...
@@ -156,7 +159,7 @@ MainWindow::MainWindow(QWidget *parent):
setCorner
(
Qt
::
BottomRightCorner
,
Qt
::
BottomDockWidgetArea
);
// Setup UI state machines
centerStackActionGroup
->
setExclusive
(
true
);
centerStackActionGroup
->
setExclusive
(
true
);
centerStack
=
new
QStackedWidget
(
this
);
setCentralWidget
(
centerStack
);
...
...
@@ -1220,45 +1223,31 @@ void MainWindow::enableAutoReconnect(bool enabled)
bool
MainWindow
::
loadStyle
(
QGC_MAINWINDOW_STYLE
style
,
QString
cssFile
)
{
qApp
->
setStyle
(
"plastique"
);
// Set up the
switch
(
style
)
{
default:
style
=
QGC_MAINWINDOW_STYLE_DARK
;
case
QGC_MAINWINDOW_STYLE_DARK
:
darkStyleFileName
=
":files/styles/style-dark.css"
;
break
;
case
QGC_MAINWINDOW_STYLE_LIGHT
:
styleFileName
=
":files/styles/style-light.css"
;
break
;
case
QGC_MAINWINDOW_STYLE_CUSTOM_DARK
:
case
QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT
:
styleFileName
=
cssFile
;
break
;
}
currentStyle
=
style
;
qApp
->
setStyle
(
"plastique"
);
return
loadStyleSheet
(
styleFileName
);
}
// Store the new style classification.
currentStyle
=
style
;
bool
MainWindow
::
loadStyleSheet
(
QString
cssFile
)
{
// Load the new stylesheet.
QFile
styleSheet
(
cssFile
);
// Attempt to open the stylesheet, replacing the 'ICONDIR' token here with the proper application path.
if
(
styleSheet
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
// Signal to the user that the app will pause to apply a new stylesheet
qApp
->
setOverrideCursor
(
Qt
::
WaitCursor
);
QString
style
=
QString
(
styleSheet
.
readAll
());
style
.
replace
(
"ICONDIR"
,
QCoreApplication
::
applicationDirPath
()
+
"files/styles/"
);
style
.
replace
(
"ICONDIR"
,
QCoreApplication
::
applicationDirPath
()
+
"files/styles/"
);
qApp
->
setStyleSheet
(
style
);
return
true
;
// And restore the cursor before returning.
qApp
->
restoreOverrideCursor
();
return
true
;
}
// Otherwise alert return a failure code.
return
false
;
return
false
;
}
/**
...
...
@@ -1499,8 +1488,8 @@ void MainWindow::addLink()
// Go fishing for this link's configuration window
QList
<
QAction
*>
actions
=
ui
.
menuNetwork
->
actions
();
const
int32_t
&
linkIndex
(
LinkManager
::
instance
()
->
getLinks
().
indexOf
(
link
));
const
int32_t
&
linkID
(
LinkManager
::
instance
()
->
getLinks
()[
linkIndex
]
->
getId
());
const
int32_t
&
linkIndex
(
LinkManager
::
instance
()
->
getLinks
().
indexOf
(
link
));
const
int32_t
&
linkID
(
LinkManager
::
instance
()
->
getLinks
()[
linkIndex
]
->
getId
());
foreach
(
QAction
*
act
,
actions
)
{
...
...
@@ -1526,8 +1515,8 @@ void MainWindow::addLink(LinkInterface *link)
bool
found
(
false
);
const
int32_t
&
linkIndex
(
LinkManager
::
instance
()
->
getLinks
().
indexOf
(
link
));
const
int32_t
&
linkID
(
LinkManager
::
instance
()
->
getLinks
()[
linkIndex
]
->
getId
());
const
int32_t
&
linkIndex
(
LinkManager
::
instance
()
->
getLinks
().
indexOf
(
link
));
const
int32_t
&
linkID
(
LinkManager
::
instance
()
->
getLinks
()[
linkIndex
]
->
getId
());
foreach
(
QAction
*
act
,
actions
)
{
...
...
@@ -1614,7 +1603,7 @@ void MainWindow::UASCreated(UASInterface* uas)
QIcon
icon
;
// Set matching icon
switch
(
uas
->
getSystemType
())
{
{
case
MAV_TYPE_GENERIC
:
icon
=
QIcon
(
":files/images/mavs/generic.svg"
);
break
;
...
...
src/ui/MainWindow.h
View file @
9d969f1f
...
...
@@ -104,13 +104,14 @@ public:
enum
QGC_MAINWINDOW_STYLE
{
QGC_MAINWINDOW_STYLE_DARK
,
QGC_MAINWINDOW_STYLE_LIGHT
,
QGC_MAINWINDOW_STYLE_CUSTOM_DARK
,
QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT
QGC_MAINWINDOW_STYLE_LIGHT
};
static
const
QString
defaultDarkStyle
;
static
const
QString
defaultLightStyle
;
/** @brief Get current visual style */
int
getStyle
()
QGC_MAINWINDOW_STYLE
getStyle
()
{
return
currentStyle
;
}
...
...
@@ -202,10 +203,9 @@ public slots:
/** @brief Save power by reducing update rates */
void
enableLowPowerMode
(
bool
enabled
)
{
lowPowerMode
=
enabled
;
}
/** @brief Load a specific style.
* If it's a custom style, load the file indicated by the cssFile path.
*/
* If it's a custom style, load the file indicated by the cssFile path.
*/
bool
loadStyle
(
QGC_MAINWINDOW_STYLE
style
,
QString
cssFile
);
bool
loadStyleSheet
(
QString
cssFile
);
/** @brief Add a custom tool widget */
void
createCustomWidget
();
...
...
@@ -328,7 +328,7 @@ protected:
void
buildCommonWidgets
();
void
connectCommonWidgets
();
void
connectCommonActions
();
void
connectSenseSoarActions
();
void
connectSenseSoarActions
();
void
loadSettings
();
void
storeSettings
();
...
...
src/ui/QGCSettingsWidget.cc
View file @
9d969f1f
...
...
@@ -47,11 +47,11 @@ QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) :
connect
(
ui
->
titleBarCheckBox
,
SIGNAL
(
clicked
(
bool
)),
MainWindow
::
instance
(),
SLOT
(
enableDockWidgetTitleBars
(
bool
)));
// Style
MainWindow
::
QGC_MAINWINDOW_STYLE
style
=
(
MainWindow
::
QGC_MAINWINDOW_STYLE
)
MainWindow
::
instance
()
->
getStyle
();
MainWindow
::
QGC_MAINWINDOW_STYLE
style
=
MainWindow
::
instance
()
->
getStyle
();
ui
->
styleChooser
->
setCurrentIndex
(
style
);
connect
(
ui
->
styleChooser
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
styleChanged
(
int
)));
connect
(
ui
->
darkS
tyleCustomButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
selectStylesheet
()));
connect
(
ui
->
lightStyleCustomButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
selectStylesheet
()));
connect
(
ui
->
styleChooser
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
styleChanged
(
int
)));
connect
(
ui
->
s
tyleCustomButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
selectStylesheet
()));
connect
(
ui
->
styleDefaultButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
setDefaultStyle
()));
// Close / destroy
connect
(
ui
->
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
deleteLater
()));
...
...
@@ -65,68 +65,96 @@ QGCSettingsWidget::~QGCSettingsWidget()
void
QGCSettingsWidget
::
selectStylesheet
()
{
// Let user select style sheet. The root directory for the file picker is the user's home directory if they haven't loaded a custom style.
// Otherwise it defaults to the directory of that custom file.
QString
findDir
;
if
(
MainWindow
::
instance
()
->
getStyle
()
==
MainWindow
::
QGC_MAINWINDOW_STYLE_CUSTOM_DARK
||
MainWindow
::
instance
()
->
getStyle
()
==
MainWindow
::
QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT
)
{
findDir
=
QDir
::
homePath
();
}
else
{
findDir
=
MainWindow
::
instance
()
->
getStyleSheet
();
}
QString
newStyleFileName
=
QFileDialog
::
getOpenFileName
(
this
,
tr
(
"Specify stylesheet"
),
findDir
,
tr
(
"CSS Stylesheet (*.css);;"
));
// Load the new style sheet if a valid one was selected.
if
(
!
newStyleFileName
.
isNull
())
// Otherwise it defaults to the directory of that custom file.
QString
findDir
;
QString
oldStylesheet
(
ui
->
styleSheetFile
->
text
());
QFile
styleSheet
(
oldStylesheet
);
if
(
styleSheet
.
exists
()
&&
oldStylesheet
[
0
]
!=
':'
)
{
QFile
styleSheet
(
newStyleFileName
);
if
(
styleSheet
.
exists
())
findDir
=
styleSheet
.
fileName
();
}
else
{
findDir
=
QDir
::
homePath
();
}
// Prompt the user to select a new style sheet. Do nothing if they cancel.
QString
newStyleFileName
=
QFileDialog
::
getOpenFileName
(
this
,
tr
(
"Specify stylesheet"
),
findDir
,
tr
(
"CSS Stylesheet (*.css);;"
));
if
(
newStyleFileName
.
isNull
())
{
return
;
}
// Load the new style sheet if a valid one was selected, notifying the user
// of an error if necessary.
QFile
newStyleFile
(
newStyleFileName
);
if
(
!
newStyleFile
.
exists
()
||
!
updateStyle
(
newStyleFileName
))
{
QMessageBox
msgBox
;
msgBox
.
setIcon
(
QMessageBox
::
Information
);
msgBox
.
setText
(
tr
(
"QGroundControl did not load a new style"
));
msgBox
.
setInformativeText
(
tr
(
"Stylesheet file %1 was not readable"
).
arg
(
newStyleFileName
));
msgBox
.
setStandardButtons
(
QMessageBox
::
Ok
);
msgBox
.
setDefaultButton
(
QMessageBox
::
Ok
);
msgBox
.
exec
();
}
// And update the UI as needed.
else
{
switch
(
ui
->
styleChooser
->
currentIndex
())
{
if
(
!
updateStyle
())
{
QMessageBox
msgBox
;
msgBox
.
setIcon
(
QMessageBox
::
Information
);
msgBox
.
setText
(
tr
(
"QGroundControl did not load a new style"
));
msgBox
.
setInformativeText
(
tr
(
"Stylesheet file %1 was not readable"
).
arg
(
newStyleFileName
));
msgBox
.
setStandardButtons
(
QMessageBox
::
Ok
);
msgBox
.
setDefaultButton
(
QMessageBox
::
Ok
);
msgBox
.
exec
();
}
case
0
:
darkStyleSheet
=
newStyleFileName
;
ui
->
styleSheetFile
->
setText
(
darkStyleSheet
);
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
,
darkStyleSheet
);
case
1
:
lightStyleSheet
=
newStyleFileName
;
ui
->
styleSheetFile
->
setText
(
lightStyleSheet
);
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
,
lightStyleSheet
);
}
else
{
QMessageBox
msgBox
;
msgBox
.
setIcon
(
QMessageBox
::
Information
);
msgBox
.
setText
(
tr
(
"QGroundControl did not load a new style"
));
msgBox
.
setInformativeText
(
tr
(
"Stylesheet file %1 was not readable"
).
arg
(
newStyleFileName
));
msgBox
.
setStandardButtons
(
QMessageBox
::
Ok
);
msgBox
.
setDefaultButton
(
QMessageBox
::
Ok
);
msgBox
.
exec
();
}
}
}
bool
QGCSettingsWidget
::
updateStyle
()
bool
QGCSettingsWidget
::
updateStyle
(
QString
style
)
{
switch
(
ui
->
styleChooser
->
currentIndex
())
{
case
0
:
return
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
,
QString
());
case
1
:
return
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
,
QString
());
case
2
:
return
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_CUSTOM_DARK
,
QString
());
case
3
:
return
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT
,
QString
());
default:
return
false
;
}
switch
(
ui
->
styleChooser
->
currentIndex
())
{
case
0
:
darkStyleSheet
=
style
;
return
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
,
darkStyleSheet
);
case
1
:
lightStyleSheet
=
style
;
return
MainWindow
::
instance
()
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
,
lightStyleSheet
);
default:
return
false
;
}
}
void
QGCSettingsWidget
::
styleChanged
(
int
index
)
{
// And trigger a style update.
updateStyle
();
}
\ No newline at end of file
{
if
(
index
==
1
)
{
ui
->
styleSheetFile
->
setText
(
lightStyleSheet
);
updateStyle
(
lightStyleSheet
);
}
else
{
ui
->
styleSheetFile
->
setText
(
darkStyleSheet
);
updateStyle
(
darkStyleSheet
);
}
}
void
QGCSettingsWidget
::
setDefaultStyle
()
{
if
(
ui
->
styleChooser
->
currentIndex
()
==
1
)
{
lightStyleSheet
=
MainWindow
::
defaultLightStyle
;
ui
->
styleSheetFile
->
setText
(
lightStyleSheet
);
updateStyle
(
lightStyleSheet
);
}
else
{
darkStyleSheet
=
MainWindow
::
defaultDarkStyle
;
ui
->
styleSheetFile
->
setText
(
darkStyleSheet
);
updateStyle
(
darkStyleSheet
);
}
}
src/ui/QGCSettingsWidget.h
View file @
9d969f1f
...
...
@@ -17,12 +17,15 @@ public:
~
QGCSettingsWidget
();
public
slots
:
void
styleChanged
(
int
index
);
void
styleChanged
(
int
index
);
void
setDefaultStyle
();
void
selectStylesheet
();
private:
Ui
::
QGCSettingsWidget
*
ui
;
void
selectStylesheet
();
bool
updateStyle
();
Ui
::
QGCSettingsWidget
*
ui
;
QString
darkStyleSheet
;
QString
lightStyleSheet
;
bool
updateStyle
(
QString
style
);
};
#endif // QGCSETTINGSWIDGET_H
src/ui/QGCSettingsWidget.ui
View file @
9d969f1f
...
...
@@ -6,8 +6,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
392
</width>
<height>
3
13
</height>
<width>
528
</width>
<height>
3
21
</height>
</rect>
</property>
<property
name=
"sizePolicy"
>
...
...
@@ -77,38 +77,18 @@
<property
name=
"title"
>
<string>
Style
</string>
</property>
<property
name=
"flat"
>
<bool>
false
</bool>
</property>
<property
name=
"checkable"
>
<bool>
false
</bool>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_3"
>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout"
>
<property
name=
"sizeConstraint"
>
<enum>
QLayout::SetMinimumSize
</enum>
</property>
<item>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Minimum"
vsizetype=
"Minimum"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Use:
</string>
</property>
</widget>
</item>
<item>
<spacer
name=
"horizontalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QComboBox"
name=
"styleChooser"
>
<item>
...
...
@@ -128,41 +108,7 @@
<item>
<layout
class=
"QHBoxLayout"
name=
"DarkStyleLayout"
>
<item>
<widget
class=
"QLabel"
name=
"label_2"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Minimum"
vsizetype=
"Minimum"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Dark:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QLineEdit"
name=
"darkStyleFile"
/>
</item>
<item>
<widget
class=
"QPushButton"
name=
"darkStyleCustomButton"
>
<property
name=
"text"
>
<string>
Custom
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"darkStyleDefaultButton"
>
<property
name=
"text"
>
<string>
Default
</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"LightStyleLayout"
>
<item>
<widget
class=
"QLabel"
name=
"label_3"
>
<widget
class=
"QLabel"
name=
"label"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Minimum"
vsizetype=
"Minimum"
>
<horstretch>
0
</horstretch>
...
...
@@ -170,22 +116,22 @@
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Ligh
t:
</string>
<string>
Styleshee
t:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QLineEdit"
name=
"
lightStyle
File"
/>
<widget
class=
"QLineEdit"
name=
"
styleSheet
File"
/>
</item>
<item>
<widget
class=
"QPushButton"
name=
"
lightS
tyleCustomButton"
>
<widget
class=
"QPushButton"
name=
"
s
tyleCustomButton"
>
<property
name=
"text"
>
<string>
Custom
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"
lightS
tyleDefaultButton"
>
<widget
class=
"QPushButton"
name=
"
s
tyleDefaultButton"
>
<property
name=
"text"
>
<string>
Default
</string>
</property>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment