mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Use dark title bar for dark theme on Windows
This commit is contained in:
parent
851cb69f8b
commit
d702b7a5d4
@ -24,14 +24,16 @@
|
||||
#include "RiaRegressionTestRunner.h"
|
||||
#include "RiaVersionInfo.h"
|
||||
|
||||
#include "RiuDockWidgetTools.h"
|
||||
#include "RiuDragDrop.h"
|
||||
#include "RiuMdiArea.h"
|
||||
#include "RiuMdiSubWindow.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
#include "RimViewWindow.h"
|
||||
|
||||
#include "RiuDockWidgetTools.h"
|
||||
#include "RiuDragDrop.h"
|
||||
#include "RiuGuiTheme.h"
|
||||
#include "RiuMainWindowTools.h"
|
||||
#include "RiuMdiArea.h"
|
||||
#include "RiuMdiSubWindow.h"
|
||||
|
||||
#include "cafCmdFeatureManager.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiTreeView.h"
|
||||
@ -83,6 +85,13 @@ RiuMainWindowBase::RiuMainWindowBase()
|
||||
m_redoAction = new QAction( QIcon( ":/redo.png" ), tr( "Redo" ), this );
|
||||
m_redoAction->setShortcut( QKeySequence::Redo );
|
||||
connect( m_redoAction, SIGNAL( triggered() ), SLOT( slotRedo() ) );
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if ( RiaPreferences::current()->guiTheme() == RiaDefines::ThemeEnum::DARK )
|
||||
{
|
||||
RiuMainWindowTools::setDarkTitleBarWindows( this );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -39,6 +39,88 @@
|
||||
#include <QMdiSubWindow>
|
||||
#include <QModelIndex>
|
||||
|
||||
// Dark title bar is taken from
|
||||
// https://envyen.com/posts/2021-10-24-QT-Windows-Dark-theme/
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <Windows.h>
|
||||
#include <dwmapi.h>
|
||||
#pragma comment( lib, "Dwmapi.lib" )
|
||||
|
||||
enum PreferredAppMode
|
||||
{
|
||||
Default,
|
||||
AllowDark,
|
||||
ForceDark,
|
||||
ForceLight,
|
||||
Max
|
||||
};
|
||||
|
||||
enum WINDOWCOMPOSITIONATTRIB
|
||||
{
|
||||
WCA_UNDEFINED = 0,
|
||||
WCA_NCRENDERING_ENABLED = 1,
|
||||
WCA_NCRENDERING_POLICY = 2,
|
||||
WCA_TRANSITIONS_FORCEDISABLED = 3,
|
||||
WCA_ALLOW_NCPAINT = 4,
|
||||
WCA_CAPTION_BUTTON_BOUNDS = 5,
|
||||
WCA_NONCLIENT_RTL_LAYOUT = 6,
|
||||
WCA_FORCE_ICONIC_REPRESENTATION = 7,
|
||||
WCA_EXTENDED_FRAME_BOUNDS = 8,
|
||||
WCA_HAS_ICONIC_BITMAP = 9,
|
||||
WCA_THEME_ATTRIBUTES = 10,
|
||||
WCA_NCRENDERING_EXILED = 11,
|
||||
WCA_NCADORNMENTINFO = 12,
|
||||
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
|
||||
WCA_VIDEO_OVERLAY_ACTIVE = 14,
|
||||
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
|
||||
WCA_DISALLOW_PEEK = 16,
|
||||
WCA_CLOAK = 17,
|
||||
WCA_CLOAKED = 18,
|
||||
WCA_ACCENT_POLICY = 19,
|
||||
WCA_FREEZE_REPRESENTATION = 20,
|
||||
WCA_EVER_UNCLOAKED = 21,
|
||||
WCA_VISUAL_OWNER = 22,
|
||||
WCA_HOLOGRAPHIC = 23,
|
||||
WCA_EXCLUDED_FROM_DDA = 24,
|
||||
WCA_PASSIVEUPDATEMODE = 25,
|
||||
WCA_USEDARKMODECOLORS = 26,
|
||||
WCA_LAST = 27
|
||||
};
|
||||
|
||||
struct WINDOWCOMPOSITIONATTRIBDATA
|
||||
{
|
||||
WINDOWCOMPOSITIONATTRIB Attrib;
|
||||
PVOID pvData;
|
||||
SIZE_T cbData;
|
||||
};
|
||||
|
||||
using fnAllowDarkModeForWindow = BOOL( WINAPI* )( HWND hWnd, BOOL allow );
|
||||
using fnSetPreferredAppMode = PreferredAppMode( WINAPI* )( PreferredAppMode appMode );
|
||||
using fnSetWindowCompositionAttribute = BOOL( WINAPI* )( HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA* );
|
||||
|
||||
static void setDarkTitlebar( HWND hwnd )
|
||||
{
|
||||
HMODULE hUxtheme = LoadLibraryExW( L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32 );
|
||||
if ( !hUxtheme ) return;
|
||||
|
||||
HMODULE hUser32 = GetModuleHandleW( L"user32.dll" );
|
||||
if ( !hUser32 ) return;
|
||||
|
||||
fnAllowDarkModeForWindow AllowDarkModeForWindow =
|
||||
reinterpret_cast<fnAllowDarkModeForWindow>( GetProcAddress( hUxtheme, MAKEINTRESOURCEA( 133 ) ) );
|
||||
fnSetPreferredAppMode SetPreferredAppMode = reinterpret_cast<fnSetPreferredAppMode>( GetProcAddress( hUxtheme, MAKEINTRESOURCEA( 135 ) ) );
|
||||
fnSetWindowCompositionAttribute SetWindowCompositionAttribute =
|
||||
reinterpret_cast<fnSetWindowCompositionAttribute>( GetProcAddress( hUser32, "SetWindowCompositionAttribute" ) );
|
||||
|
||||
SetPreferredAppMode( AllowDark );
|
||||
BOOL dark = TRUE;
|
||||
AllowDarkModeForWindow( hwnd, dark );
|
||||
WINDOWCOMPOSITIONATTRIBDATA data = { WCA_USEDARKMODECOLORS, &dark, sizeof( dark ) };
|
||||
SetWindowCompositionAttribute( hwnd, &data );
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -156,3 +238,15 @@ void RiuMainWindowTools::setFixedWindowSizeFor3dViews( RiuMainWindowBase* mainWi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMainWindowTools::setDarkTitleBarWindows( QWidget* widget )
|
||||
{
|
||||
if ( !widget ) return;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
setDarkTitlebar( reinterpret_cast<HWND>( widget->winId() ) );
|
||||
#endif
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class PdmUiItem;
|
||||
} // namespace caf
|
||||
|
||||
class RiuMainWindowBase;
|
||||
|
||||
class QWidget;
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -35,4 +35,5 @@ public:
|
||||
|
||||
static void setWindowSizeOnWidgetsInMdiWindows( RiuMainWindowBase* mainWindow, int width, int height );
|
||||
static void setFixedWindowSizeFor3dViews( RiuMainWindowBase* mainWindow, int width, int height );
|
||||
static void setDarkTitleBarWindows( QWidget* widget );
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user