Skip to content

Commit

Permalink
Merge pull request TrenchBroom#2920 from kduske/feature/qt-style-sheets
Browse files Browse the repository at this point in the history
Qt style sheet support fixup
  • Loading branch information
kduske authored Jan 5, 2020
2 parents 0fe083c + 5ab73b7 commit c382f93
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 15 deletions.
13 changes: 13 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if(APPLE)
set_source_files_properties(${MACOSX_SHADER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/shader)
set(APP_SOURCE ${APP_SOURCE} ${MACOSX_SHADER_FILES})

# Configure Qt stylesheets
file (GLOB_RECURSE MACOSX_STYLESHEET_FILES
"${APP_RESOURCE_DIR}/stylesheets/*.qss")
set_source_files_properties(${MACOSX_STYLESHEET_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/stylesheets)
set(APP_SOURCE ${APP_SOURCE} ${MACOSX_STYLESHEET_FILES})

# Configure manual files
set_source_files_properties(${INDEX_OUTPUT_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/manual)
set_source_files_properties(${DOC_MANUAL_TARGET_FILES_ABSOLUTE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/manual)
Expand Down Expand Up @@ -174,6 +180,11 @@ macro(configure_app_target APP_TARGET_NAME)
add_custom_command(TARGET ${APP_TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${APP_RESOURCE_DIR}/shader" "${APP_RESOURCE_DEST_DIR}/shader")

# Copy Qt stylesheet files to resources directory
add_custom_command(TARGET ${APP_TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${APP_RESOURCE_DEST_DIR}/stylesheets/"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${APP_RESOURCE_DIR}/stylesheets" "${APP_RESOURCE_DEST_DIR}/stylesheets")

# Copy manual files to resource directory
add_custom_command(TARGET ${APP_TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${APP_RESOURCE_DEST_DIR}/manual/"
Expand Down Expand Up @@ -273,6 +284,7 @@ if(WIN32)
"${APP_DIR}/resources/fonts"
"${APP_DIR}/resources/games"
"${APP_DIR}/resources/shader"
"${APP_DIR}/resources/stylesheets"
DESTINATION . COMPONENT TrenchBroom)
set(CPACK_GENERATOR "7Z")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
Expand Down Expand Up @@ -309,6 +321,7 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/manual" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/images" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/shader" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/stylesheets" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom)
install(DIRECTORY "${APP_DIR}/resources/linux/icons" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom FILES_MATCHING PATTERN "*.png")
install(FILES "${CMAKE_SOURCE_DIR}/LICENSE.txt" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom)
install(FILES "${APP_DIR}/resources/linux/copyright" DESTINATION ${LINUX_RESOURCE_LOCATION} COMPONENT TrenchBroom)
Expand Down
19 changes: 19 additions & 0 deletions app/resources/stylesheets/base.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
QTableView {
border: none;
}

QListWidget {
border: none;
}

QListWidget#controlListBox_listWidget {
border: none;
}

QCheckBox#entityDefinition_checkboxWidget {
margin-left: 11px;
}

QToolButton#toolButton_borderless {
border: none;
}
20 changes: 19 additions & 1 deletion common/src/TrenchBroomApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ namespace TrenchBroom {
return;
}

loadStyleSheets();

// these must be initialized here and not earlier
m_frameManager = std::make_unique<FrameManager>(useSDI());

Expand Down Expand Up @@ -168,7 +170,23 @@ namespace TrenchBroom {
return m_frameManager.get();
}

const std::vector<IO::Path>& TrenchBroomApp::recentDocuments() const {
bool TrenchBroomApp::loadStyleSheets() {
const auto path = IO::SystemPaths::findResourceFile(IO::Path("stylesheets/base.qss"));
auto file = QFile(IO::pathAsQString(path));
if (file.exists()) {
// closed automatically by destructor
file.open(QFile::ReadOnly | QFile::Text);

const auto text = QTextStream(&file).readAll();
qApp->setStyleSheet(text);

return true;
} else {
return false;
}
}

const std::vector<IO::Path>& TrenchBroomApp::recentDocuments() const {
return m_recentDocuments->recentDocuments();
}

Expand Down
2 changes: 2 additions & 0 deletions common/src/TrenchBroomApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace TrenchBroom {

FrameManager* frameManager();

bool loadStyleSheets();

const std::vector<IO::Path>& recentDocuments() const;
void addRecentDocumentMenu(QMenu* menu);
void removeRecentDocumentMenu(QMenu* menu);
Expand Down
2 changes: 1 addition & 1 deletion common/src/View/BorderLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace TrenchBroom {
QFrame(parent) {
setContentsMargins(0, 0, 0, 0);
setFrameShadow(QFrame::Plain);
setStyleSheet(" BorderLine { color: " + Colors::borderColor().name() + "; }");
setStyleSheet("BorderLine { color: " + Colors::borderColor().name() + "; }");
setLineWidth(thickness - 1);
if (direction == Direction::Horizontal) {
setFrameShape(QFrame::HLine);
Expand Down
2 changes: 0 additions & 2 deletions common/src/View/ControlListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ namespace TrenchBroom {
auto* emptyTextLayout = new QVBoxLayout();
m_emptyTextContainer->setLayout(emptyTextLayout);
emptyTextLayout->addWidget(m_emptyTextLabel);

setStyleSheet("QListWidget#controlListBox_listWidget { border: none; }");
}

ControlListBox::ControlListBox(const QString& emptyText, const bool showSeparator, QWidget* parent) :
Expand Down
2 changes: 0 additions & 2 deletions common/src/View/DirectoryTextureCollectionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ namespace TrenchBroom {
auto* availableCollectionsContainer = new TitledPanel("Available", false, false);

m_availableCollectionsList = new QListWidget();
m_availableCollectionsList->setStyleSheet("QListWidget { border: none; }");
m_availableCollectionsList->setSelectionMode(QAbstractItemView::ExtendedSelection);

auto* availableCollectionsContainerLayout = new QVBoxLayout();
Expand All @@ -133,7 +132,6 @@ namespace TrenchBroom {

auto* enabledCollectionsContainer = new TitledPanel("Enabled", false, false);
m_enabledCollectionsList = new QListWidget();
m_enabledCollectionsList->setStyleSheet("QListWidget { border: none; }");
m_enabledCollectionsList->setSelectionMode(QAbstractItemView::ExtendedSelection);

auto* enabledCollectionsContainerLayout = new QVBoxLayout();
Expand Down
1 change: 0 additions & 1 deletion common/src/View/EntityAttributeGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ namespace TrenchBroom {

autoResizeRows(m_table);

m_table->setStyleSheet("QTableView { border: none; }");
m_table->verticalHeader()->setVisible(false);
m_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
m_table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
Expand Down
1 change: 0 additions & 1 deletion common/src/View/FileTextureCollectionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ namespace TrenchBroom {

void FileTextureCollectionEditor::createGui() {
m_collections = new QListWidget();
m_collections->setStyleSheet("QListWidget { border: none; }");
m_collections->setSelectionMode(QAbstractItemView::ExtendedSelection);

m_addTextureCollectionsButton = createBitmapButton("Add.png", "Add texture collections from the file system");
Expand Down
1 change: 0 additions & 1 deletion common/src/View/KeyboardPreferencePane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace TrenchBroom {

autoResizeRows(m_table);

m_table->setStyleSheet("QTableView { border: none; }");
m_table->setHorizontalHeader(new QHeaderView(Qt::Horizontal));
m_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents);
m_table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents);
Expand Down
2 changes: 0 additions & 2 deletions common/src/View/ModEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ namespace TrenchBroom {
void ModEditor::createGui() {
auto* availableModContainer = new TitledPanel("Available", false, false);
m_availableModList = new QListWidget();
m_availableModList->setStyleSheet("QListWidget { border: none; }");
m_availableModList->setSelectionMode(QAbstractItemView::ExtendedSelection);

auto* availableModContainerSizer = new QVBoxLayout();
Expand All @@ -81,7 +80,6 @@ namespace TrenchBroom {

auto* enabledModContainer = new TitledPanel("Enabled", false, false);
m_enabledModList = new QListWidget();
m_enabledModList->setStyleSheet("QListWidget { border: none; }");
m_enabledModList->setSelectionMode(QAbstractItemView::ExtendedSelection);

auto* enabledModContainerSizer = new QVBoxLayout();
Expand Down
2 changes: 1 addition & 1 deletion common/src/View/QtUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace TrenchBroom {
button->setToolTip(tooltip);
button->setIcon(icon);
// button->setFlat(true);
button->setStyleSheet("QToolButton { border: none; }");
button->setObjectName("toolButton_borderless");

return button;
}
Expand Down
2 changes: 0 additions & 2 deletions common/src/View/RecentDocumentListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "IO/Path.h"
#include "IO/PathQt.h"
#include "IO/ResourceUtils.h"
#include "Model/GameFactory.h"

#include <cassert>

Expand All @@ -33,7 +32,6 @@ namespace TrenchBroom {
RecentDocumentListBox::RecentDocumentListBox(QWidget* parent) :
ImageListBox("No Recent Documents", true, parent),
m_documentIcon(IO::loadPixmapResource("DocIcon.png")) {
assert(!m_documentIcon.isNull());
TrenchBroomApp& app = View::TrenchBroomApp::instance();
connect(&app, &TrenchBroomApp::recentDocumentsDidChange, this, &RecentDocumentListBox::recentDocumentsDidChange);
reload();
Expand Down
2 changes: 1 addition & 1 deletion common/src/View/ViewEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace TrenchBroom {
const std::string defName = definition->name();

auto* defCB = new QCheckBox(QString::fromStdString(defName));
defCB->setStyleSheet("margin-left: 11px");
defCB->setObjectName("entityDefinition_checkboxWidget");

connect(defCB, &QAbstractButton::clicked, this, [this, definition](bool checked){
this->defCheckBoxChanged(definition, checked);
Expand Down

0 comments on commit c382f93

Please sign in to comment.