Support building with wxQT wxWidgets port (experimental).

This commit is contained in:
Alex Shvartzkop 2024-06-01 10:47:43 +03:00
parent f192c5b174
commit 2b957e520c
5 changed files with 458 additions and 0 deletions

View File

@ -38,6 +38,27 @@ elseif( KICAD_WX_PORT STREQUAL gtk )
message( STATUS "Configuring KiCad not to hide any GTK error messages" )
string( APPEND PLATFORM_COMPILE_DEFS "-DKICAD_SHOW_GTK_MESSAGES" )
endif()
elseif( KICAD_WX_PORT STREQUAL qt )
set( PLATFORM_SRCS
port/wxqt/ui.cpp
)
set( QT_COMPONENTS Core Widgets Gui )
find_package( Qt5 REQUIRED COMPONENTS ${QT_COMPONENTS} )
set( QT_MAJOR_VERSION 5 )
foreach(QT_COMPONENT ${QT_COMPONENTS})
list(APPEND QT_INC_DIRS ${Qt${QT_MAJOR_VERSION}${QT_COMPONENT}_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBS ${Qt${QT_MAJOR_VERSION}${QT_COMPONENT}_LIBRARIES})
list(APPEND PLATFORM_COMPILE_DEFS ${Qt${QT_MAJOR_VERSION}${QT_COMPONENT}_COMPILE_DEFINITIONS})
endforeach()
include_directories( SYSTEM ${QT_INC_DIRS} )
message( STATUS "Using Qt${QT_MAJOR_VERSION} platform libraries ${PLATFORM_LIBS}" )
endif()

View File

@ -0,0 +1,131 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Mark Roszko <mark.roszko@gmail.com>
* Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <kiplatform/app.h>
#include <wx/string.h>
#include <wx/utils.h>
#ifdef _WIN32
#include <windows.h>
#include <strsafe.h>
#include <config.h>
#include <VersionHelpers.h>
#include <iostream>
#include <cstdio>
#endif
bool KIPLATFORM::APP::Init()
{
AttachConsole( true );
return true;
}
bool KIPLATFORM::APP::AttachConsole( bool aTryAlloc )
{
#ifdef _WIN32
if( ::AttachConsole( ATTACH_PARENT_PROCESS ) || ( aTryAlloc && ::AllocConsole() ) )
{
#if !defined( __MINGW32__ ) // These redirections create problems on mingw:
// Nothing is printed to the console
if( ::GetStdHandle( STD_INPUT_HANDLE ) != INVALID_HANDLE_VALUE )
{
freopen( "CONIN$", "r", stdin );
setvbuf( stdin, NULL, _IONBF, 0 );
}
if( ::GetStdHandle( STD_OUTPUT_HANDLE ) != INVALID_HANDLE_VALUE )
{
freopen( "CONOUT$", "w", stdout );
setvbuf( stdout, NULL, _IONBF, 0 );
}
if( ::GetStdHandle( STD_ERROR_HANDLE ) != INVALID_HANDLE_VALUE )
{
freopen( "CONOUT$", "w", stderr );
setvbuf( stderr, NULL, _IONBF, 0 );
}
#endif
std::ios::sync_with_stdio( true );
std::wcout.clear();
std::cout.clear();
std::wcerr.clear();
std::cerr.clear();
std::wcin.clear();
std::cin.clear();
return true;
}
#endif
return false;
}
bool KIPLATFORM::APP::IsOperatingSystemUnsupported()
{
// Not implemented on this platform
return false;
}
bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine )
{
// Not implemented on this platform
return true;
}
bool KIPLATFORM::APP::UnregisterApplicationRestart()
{
// Not implemented on this platform
return true;
}
bool KIPLATFORM::APP::SupportsShutdownBlockReason()
{
return false;
}
void KIPLATFORM::APP::RemoveShutdownBlockReason( wxWindow* aWindow )
{
}
void KIPLATFORM::APP::SetShutdownBlockReason( wxWindow* aWindow, const wxString& aReason )
{
}
void KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary()
{
}
void KIPLATFORM::APP::AddDynamicLibrarySearchPath( const wxString& aPath )
{
}

View File

@ -0,0 +1,93 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <kiplatform/environment.h>
#include <wx/filename.h>
#include <wx/utils.h>
#include "qtconv.h"
#include <QString>
#include <QFile>
#include <QStandardPaths>
void KIPLATFORM::ENV::Init()
{
}
bool KIPLATFORM::ENV::MoveToTrash( const wxString& aPath, wxString& aError )
{
return QFile::moveToTrash( QString( wxString( aPath.fn_str() ) ) );
}
bool KIPLATFORM::ENV::IsNetworkPath( const wxString& aPath )
{
// placeholder, we "nerf" behavior if its a network path so return false by default
return false;
}
wxString KIPLATFORM::ENV::GetDocumentsPath()
{
return wxQtConvertString(
QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ) );
}
wxString KIPLATFORM::ENV::GetUserConfigPath()
{
return wxQtConvertString(
QStandardPaths::writableLocation( QStandardPaths::AppConfigLocation ) );
}
wxString KIPLATFORM::ENV::GetUserDataPath()
{
return wxQtConvertString(
QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation ) );
}
wxString KIPLATFORM::ENV::GetUserLocalDataPath()
{
return wxQtConvertString(
QStandardPaths::writableLocation( QStandardPaths::GenericDataLocation ) );
}
wxString KIPLATFORM::ENV::GetUserCachePath()
{
return wxQtConvertString(
QStandardPaths::writableLocation( QStandardPaths::CacheLocation ) );
}
bool KIPLATFORM::ENV::GetSystemProxyConfig( const wxString& aURL, PROXY_CONFIG& aCfg )
{
return false;
}
bool KIPLATFORM::ENV::VerifyFileSignature( const wxString& aPath )
{
return true;
}

View File

@ -0,0 +1,33 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <wx/string.h>
#include <QString>
inline wxString wxQtConvertString( const QString& str )
{
return wxString( str.toUtf8().data(), wxConvUTF8 );
}
inline QString wxQtConvertString( const wxString& str )
{
return QString( str.utf8_str() );
}

View File

@ -0,0 +1,180 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
* Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <kiplatform/ui.h>
#include <wx/choice.h>
#include <wx/nonownedwnd.h>
#include <wx/settings.h>
#include <wx/window.h>
#include <wx/log.h>
#include <QtWidgets>
#include <QCursor>
bool KIPLATFORM::UI::IsDarkTheme()
{
wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
// Weighted W3C formula
double brightness = ( bg.Red() / 255.0 ) * 0.299 +
( bg.Green() / 255.0 ) * 0.587 +
( bg.Blue() / 255.0 ) * 0.117;
return brightness < 0.5;
}
wxColour KIPLATFORM::UI::GetDialogBGColour()
{
return wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
}
void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
{
aWindow->SetFocus();
}
bool KIPLATFORM::UI::IsWindowActive( wxWindow* aWindow )
{
if( !aWindow )
return false;
QWidget* widget = aWindow->GetHandle();
if( !widget )
return false;
return widget->isActiveWindow();
}
void KIPLATFORM::UI::ReparentQuasiModal( wxNonOwnedWindow* aWindow )
{
// Not needed on this platform
}
void KIPLATFORM::UI::FixupCancelButtonCmdKeyCollision( wxWindow *aWindow )
{
// Not needed on this platform
}
bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
{
switch( aCursor )
{
case wxCURSOR_BULLSEYE:
case wxCURSOR_HAND:
case wxCURSOR_ARROW:
case wxCURSOR_BLANK:
return true;
default:
return false;
}
}
void KIPLATFORM::UI::LargeChoiceBoxHack( wxChoice* aChoice )
{
}
void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
{
}
double KIPLATFORM::UI::GetPixelScaleFactor( const wxWindow* aWindow )
{
return aWindow->GetContentScaleFactor();
}
double KIPLATFORM::UI::GetContentScaleFactor( const wxWindow* aWindow )
{
return aWindow->GetDPIScaleFactor();
}
wxSize KIPLATFORM::UI::GetUnobscuredSize( const wxWindow* aWindow )
{
return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
}
void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay )
{
}
bool KIPLATFORM::UI::AllowIconsInMenus()
{
return true;
}
bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY )
{
aWindow->WarpPointer( aX, aY );
return true;
}
void KIPLATFORM::UI::ImmControl( wxWindow* aWindow, bool aEnable )
{
// Not implemented
}
void KIPLATFORM::UI::ImeNotifyCancelComposition( wxWindow* aWindow )
{
// Not implemented
}
bool KIPLATFORM::UI::InfiniteDragPrepareWindow( wxWindow* aWindow )
{
return true;
}
void KIPLATFORM::UI::InfiniteDragReleaseWindow()
{
// Not needed
}
void KIPLATFORM::UI::SetFloatLevel( wxWindow* aWindow )
{
// Not needed
}
wxPoint KIPLATFORM::UI::GetMousePosition()
{
return wxGetMousePosition();
}