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
b38d75b3
Commit
b38d75b3
authored
Nov 19, 2014
by
Don Gagne
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #980 from DonLakeFlyer/StyleFix
Create master/slave relationship for styles
parents
ca0bc683
120a417b
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
438 deletions
+110
-438
style-dark.css
files/styles/style-dark.css
+6
-0
style-light.css
files/styles/style-light.css
+64
-228
MainWindow.cc
src/ui/MainWindow.cc
+37
-44
MainWindow.h
src/ui/MainWindow.h
+2
-17
QGCSettingsWidget.cc
src/ui/QGCSettingsWidget.cc
+1
-106
QGCSettingsWidget.h
src/ui/QGCSettingsWidget.h
+0
-3
QGCSettingsWidget.ui
src/ui/QGCSettingsWidget.ui
+0
-40
No files found.
files/styles/style-dark.css
View file @
b38d75b3
/*
This is the master style sheet as well as the dark style. This style sheet should contain both
color and size/positioning information for all styled controls. This sheet is always loaded first
Then the user specified style sheet is loaded after it to override and color settings.
*/
*
{
background-color
:
#222
;
color
:
#FFF
;
...
...
files/styles/style-light.css
View file @
b38d75b3
This diff is collapsed.
Click to expand it.
src/ui/MainWindow.cc
View file @
b38d75b3
...
...
@@ -121,8 +121,6 @@ MainWindow::MainWindow(QWidget *parent):
changingViewsFlag
(
false
),
mavlink
(
new
MAVLinkProtocol
()),
centerStackActionGroup
(
new
QActionGroup
(
this
)),
darkStyleFileName
(
defaultDarkStyle
),
lightStyleFileName
(
defaultLightStyle
),
autoReconnect
(
false
),
simulationLink
(
NULL
),
lowPowerMode
(
false
),
...
...
@@ -141,14 +139,7 @@ void MainWindow::init()
emit
initStatusChanged
(
tr
(
"Loading style"
),
Qt
::
AlignLeft
|
Qt
::
AlignBottom
,
QColor
(
62
,
93
,
141
));
qApp
->
setStyle
(
"plastique"
);
if
(
currentStyle
==
QGC_MAINWINDOW_STYLE_LIGHT
)
{
loadStyle
(
currentStyle
,
lightStyleFileName
);
}
else
{
loadStyle
(
currentStyle
,
darkStyleFileName
);
}
loadStyle
(
currentStyle
);
if
(
settings
.
contains
(
"ADVANCED_MODE"
))
{
...
...
@@ -961,8 +952,6 @@ void MainWindow::loadSettings()
settings
.
beginGroup
(
"QGC_MAINWINDOW"
);
autoReconnect
=
settings
.
value
(
"AUTO_RECONNECT"
,
autoReconnect
).
toBool
();
currentStyle
=
(
QGC_MAINWINDOW_STYLE
)
settings
.
value
(
"CURRENT_STYLE"
,
currentStyle
).
toInt
();
darkStyleFileName
=
settings
.
value
(
"DARK_STYLE_FILENAME"
,
darkStyleFileName
).
toString
();
lightStyleFileName
=
settings
.
value
(
"LIGHT_STYLE_FILENAME"
,
lightStyleFileName
).
toString
();
lowPowerMode
=
settings
.
value
(
"LOW_POWER_MODE"
,
lowPowerMode
).
toBool
();
bool
dockWidgetTitleBarEnabled
=
settings
.
value
(
"DOCK_WIDGET_TITLEBARS"
,
menuActionHelper
->
dockWidgetTitleBarsEnabled
()).
toBool
();
settings
.
endGroup
();
...
...
@@ -975,8 +964,6 @@ void MainWindow::storeSettings()
settings
.
beginGroup
(
"QGC_MAINWINDOW"
);
settings
.
setValue
(
"AUTO_RECONNECT"
,
autoReconnect
);
settings
.
setValue
(
"CURRENT_STYLE"
,
currentStyle
);
settings
.
setValue
(
"DARK_STYLE_FILENAME"
,
darkStyleFileName
);
settings
.
setValue
(
"LIGHT_STYLE_FILENAME"
,
lightStyleFileName
);
settings
.
endGroup
();
if
(
!
aboutToCloseFlag
&&
isVisible
())
{
...
...
@@ -1065,43 +1052,49 @@ void MainWindow::enableAutoReconnect(bool enabled)
autoReconnect
=
enabled
;
}
bool
MainWindow
::
loadStyle
(
QGC_MAINWINDOW_STYLE
style
,
QString
cssFile
)
bool
MainWindow
::
loadStyle
(
QGC_MAINWINDOW_STYLE
style
)
{
qDebug
()
<<
"LOAD STYLE"
<<
style
;
bool
success
=
true
;
QString
styles
;
// Signal to the user that the app will pause to apply a new stylesheet
qApp
->
setOverrideCursor
(
Qt
::
WaitCursor
);
// Store the new style classification.
currentStyle
=
style
;
//
Load the new stylesheet.
QFile
styleSheet
(
cssFile
);
// Attempt to open the stylesheet.
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
)
;
qApp
->
setStyleSheet
(
styleSheet
.
readAll
());
// And save the new stylesheet path.
if
(
currentStyle
==
QGC_MAINWINDOW_STYLE_LIGHT
)
{
lightStyleFileName
=
cssFile
;
}
else
{
darkStyleFileName
=
cssFil
e
;
//
The dark style sheet is the master. Any other selected style sheet just overrides
// the colors of the master sheet.
QFile
masterStyleSheet
(
defaultDarkStyle
);
if
(
masterStyleSheet
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
styles
=
masterStyleSheet
.
readAll
();
}
else
{
qDebug
()
<<
"Unable to load master dark style sheet"
;
success
=
false
;
}
if
(
success
&&
style
==
QGC_MAINWINDOW_STYLE_LIGHT
)
{
qDebug
()
<<
"LOADING LIGHT"
;
// Load the slave light stylesheet.
QFile
styleSheet
(
defaultLightStyle
);
if
(
styleSheet
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
styles
+=
styleSheet
.
readAll
();
}
else
{
qDebug
()
<<
"Unable to load slave light sheet:"
;
success
=
fals
e
;
}
}
// And trigger any changes to other UI elements that are watching for
// theme changes.
if
(
!
styles
.
isEmpty
())
{
qApp
->
setStyleSheet
(
styles
);
emit
styleChanged
(
style
);
// Finally restore the cursor before returning.
qApp
->
restoreOverrideCursor
();
return
true
;
}
// Otherwise alert return a failure code.
return
false
;
// Finally restore the cursor before returning.
qApp
->
restoreOverrideCursor
();
return
success
;
}
/**
...
...
src/ui/MainWindow.h
View file @
b38d75b3
...
...
@@ -142,17 +142,6 @@ public:
return
currentStyle
;
}
/** @brief Get current light visual stylesheet */
QString
getLightStyleSheet
()
const
{
return
lightStyleFileName
;
}
/** @brief Get current dark visual stylesheet */
QString
getDarkStyleSheet
()
const
{
return
darkStyleFileName
;
}
/** @brief Get auto link reconnect setting */
bool
autoReconnectEnabled
()
const
{
...
...
@@ -249,10 +238,8 @@ 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.
*/
bool
loadStyle
(
QGC_MAINWINDOW_STYLE
style
,
QString
cssFile
);
/** @brief Load the specified style. */
bool
loadStyle
(
QGC_MAINWINDOW_STYLE
style
);
/** @brief Add a custom tool widget */
void
createCustomWidget
();
...
...
@@ -481,8 +468,6 @@ protected:
LogCompressor
*
comp
;
QString
screenFileName
;
QTimer
*
videoTimer
;
QString
darkStyleFileName
;
QString
lightStyleFileName
;
bool
autoReconnect
;
MAVLinkSimulationLink
*
simulationLink
;
Qt
::
WindowStates
windowStateVal
;
...
...
src/ui/QGCSettingsWidget.cc
View file @
b38d75b3
...
...
@@ -72,20 +72,9 @@ QGCSettingsWidget::QGCSettingsWidget(JoystickInput *joystick, QWidget *parent, Q
// Intialize the style UI to the proper values obtained from the MainWindow.
MainWindow
::
QGC_MAINWINDOW_STYLE
style
=
mainWindow
->
getStyle
();
ui
->
styleChooser
->
setCurrentIndex
(
style
);
if
(
style
==
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
)
{
ui
->
styleSheetFile
->
setText
(
mainWindow
->
getDarkStyleSheet
());
}
else
{
ui
->
styleSheetFile
->
setText
(
mainWindow
->
getLightStyleSheet
());
}
// And then connect all the signals for the UI for changing styles.
connect
(
ui
->
styleChooser
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
styleChanged
(
int
)));
connect
(
ui
->
styleCustomButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
selectStylesheet
()));
connect
(
ui
->
styleDefaultButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
setDefaultStyle
()));
connect
(
ui
->
styleSheetFile
,
SIGNAL
(
editingFinished
()),
this
,
SLOT
(
lineEditFinished
()));
// Close / destroy
connect
(
ui
->
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
deleteLater
()));
...
...
@@ -96,103 +85,9 @@ QGCSettingsWidget::~QGCSettingsWidget()
delete
ui
;
}
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
;
QString
oldStylesheet
(
ui
->
styleSheetFile
->
text
());
QFile
styleSheet
(
oldStylesheet
);
if
(
styleSheet
.
exists
()
&&
oldStylesheet
[
0
]
!=
':'
)
{
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
{
ui
->
styleSheetFile
->
setText
(
newStyleFileName
);
}
}
bool
QGCSettingsWidget
::
updateStyle
(
QString
style
)
{
switch
(
ui
->
styleChooser
->
currentIndex
())
{
case
0
:
return
mainWindow
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
,
style
);
case
1
:
return
mainWindow
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
,
style
);
default:
return
false
;
}
}
void
QGCSettingsWidget
::
lineEditFinished
()
{
QString
newStyleFileName
(
ui
->
styleSheetFile
->
text
());
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
();
}
}
void
QGCSettingsWidget
::
styleChanged
(
int
index
)
{
if
(
index
==
1
)
{
ui
->
styleSheetFile
->
setText
(
mainWindow
->
getLightStyleSheet
());
mainWindow
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
,
mainWindow
->
getLightStyleSheet
());
}
else
{
ui
->
styleSheetFile
->
setText
(
mainWindow
->
getDarkStyleSheet
());
mainWindow
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
,
mainWindow
->
getDarkStyleSheet
());
}
}
void
QGCSettingsWidget
::
setDefaultStyle
()
{
if
(
ui
->
styleChooser
->
currentIndex
()
==
1
)
{
ui
->
styleSheetFile
->
setText
(
MainWindow
::
defaultLightStyle
);
mainWindow
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
,
MainWindow
::
defaultLightStyle
);
}
else
{
ui
->
styleSheetFile
->
setText
(
MainWindow
::
defaultDarkStyle
);
mainWindow
->
loadStyle
(
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
,
MainWindow
::
defaultDarkStyle
);
}
mainWindow
->
loadStyle
((
index
==
1
)
?
MainWindow
::
QGC_MAINWINDOW_STYLE_LIGHT
:
MainWindow
::
QGC_MAINWINDOW_STYLE_DARK
);
}
void
QGCSettingsWidget
::
selectCustomMode
(
int
mode
)
...
...
src/ui/QGCSettingsWidget.h
View file @
b38d75b3
...
...
@@ -19,9 +19,6 @@ public:
public
slots
:
void
styleChanged
(
int
index
);
void
lineEditFinished
();
void
setDefaultStyle
();
void
selectStylesheet
();
void
selectCustomMode
(
int
mode
);
private
slots
:
...
...
src/ui/QGCSettingsWidget.ui
View file @
b38d75b3
...
...
@@ -108,46 +108,6 @@
</item>
</layout>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"DarkStyleLayout"
>
<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>
Stylesheet:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QLineEdit"
name=
"styleSheetFile"
/>
</item>
<item>
<widget
class=
"QPushButton"
name=
"styleCustomButton"
>
<property
name=
"text"
>
<string>
Custom
</string>
</property>
<property
name=
"autoDefault"
>
<bool>
false
</bool>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"styleDefaultButton"
>
<property
name=
"text"
>
<string>
Default
</string>
</property>
<property
name=
"autoDefault"
>
<bool>
false
</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
...
...
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