diff src/ui_utils.cpp @ 2:23d0d9319a00

Update Also converted everything to LF from CRLF
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 03:16:26 -0400
parents 1ae666fdf9e2
children 1d82f6e04d7d
line wrap: on
line diff
--- a/src/ui_utils.cpp	Tue Aug 08 19:49:15 2023 -0400
+++ b/src/ui_utils.cpp	Sat Aug 12 03:16:26 2023 -0400
@@ -1,32 +1,88 @@
-#include "window.h"
-#include "ui_utils.h"
-
-void UiUtils::CreateTextHeader(wxWindow* parent, const wchar_t* title, int width, int x, int y) {
-	wxStaticText* static_text_title  = new wxStaticText(parent, wxID_ANY, title, wxPoint(x, y), wxSize(width, 15), wxALIGN_LEFT);
-	wxFont font = static_text_title->GetFont();
-	font.SetWeight(wxFONTWEIGHT_BOLD);
-	static_text_title->SetFont(font);
-	//wxStaticLine* line = new wxStaticLine(parent, wxID_ANY, wxPoint(x,y+15), wxSize(width, 2), wxLI_HORIZONTAL);
-	wxClientDC dc(parent);
-	dc.DrawRectangle(x, y+15, width, 2);
-}
-
-wxStaticText* UiUtils::CreateTextParagraph(wxWindow* parent, const wchar_t* title, const wchar_t* data, int width, int height, int x, int y) {
-	CreateTextHeader(parent, title, width, x, y);
-	return new wxStaticText(parent, wxID_ANY, data, wxPoint(x+23, y+30), wxSize(width-23, height), wxALIGN_LEFT);
-}
-
-wxStaticText* UiUtils::CreateTextParagraphWithLabels(wxWindow* parent, const wchar_t* title, const wchar_t* label, const wchar_t* data, int width, int height, int x, int y) {
-	CreateTextHeader(parent, title, width, x, y);
-	new wxStaticText(parent, wxID_ANY, label, wxPoint(x+23, y+30), wxSize(width-23, height), wxALIGN_LEFT);
-	return new wxStaticText(parent, wxID_ANY, data, wxPoint(x+157, y+30), wxSize(width-157, height), wxALIGN_LEFT);
-}
-
-/* As far as I can tell, this is identical to the way Taiga implements it.
-   Kind of cool, I didn't even look into the source code for it :p */
-wxTextCtrl* UiUtils::CreateSelectableTextParagraph(wxWindow* parent, const wchar_t* title, const wchar_t* data, int width, int height, int x, int y) {
-	CreateTextHeader(parent, title, width, x, y);
-	wxTextCtrl* textctrl = new wxTextCtrl(parent, wxID_ANY, "", wxPoint(x+23, y+30), wxSize(width-23, height), wxTE_LEFT | wxBORDER_NONE | wxTE_BESTWRAP | wxTE_READONLY | wxTE_MULTILINE | wxTE_NO_VSCROLL);
-	(*textctrl) << data;
-	return textctrl;
-}
+#include "window.h"
+#include "ui_utils.h"
+#ifdef MACOSX
+#include "sys/osx/dark_theme.h"
+#else
+#include "sys/win32/dark_theme.h"
+#endif
+
+bool UiUtils::IsInDarkMode() {
+	if (session.config.theme != OS)
+		return (session.config.theme == DARK);
+#ifdef MACOSX
+	if (osx::DarkThemeAvailable()) {
+		if (osx::IsInDarkTheme()) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+#elif defined(WIN32)
+	if (win32::DarkThemeAvailable()) {
+		if (win32::IsInDarkTheme()) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+#endif
+	return (session.config.theme == DARK);
+}
+
+void UiUtils::CreateTextHeader(QWidget* parent, QString title, QPoint point, QSize size) {
+	QLabel* static_text_title  = new QLabel(title, parent);
+	static_text_title->setTextFormat(Qt::PlainText);
+	static_text_title->setStyleSheet("font-weight: bold");
+	static_text_title->move(point.x(), point.y());
+	static_text_title->resize(size.width(), 16);
+
+	QFrame* static_text_line = new QFrame(parent);
+	static_text_line->setFrameShape(QFrame::HLine);
+	static_text_line->setFrameShadow(QFrame::Sunken);
+	static_text_line->resize(size.width(), 2);
+	static_text_line->move(point.x(), point.y()+18);
+}
+
+QPlainTextEdit* UiUtils::CreateTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) {
+	CreateTextHeader(parent, title, point, size);
+
+	QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent);
+	paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
+	paragraph->setWordWrapMode(QTextOption::NoWrap);
+	paragraph->setFrameShape(QFrame::NoFrame);
+	paragraph->move(point.x()+12, point.y()+32);
+	paragraph->resize(size.width()-12, size.height()-32);
+	return paragraph;
+}
+
+QPlainTextEdit* UiUtils::CreateTextParagraphWithLabels(QWidget* parent, QString title, QString label, QString data, QPoint point, QSize size) {
+	CreateTextHeader(parent, title, point, size);
+
+	QPlainTextEdit* label_t = new QPlainTextEdit(label, parent);
+	label_t->setTextInteractionFlags(Qt::NoTextInteraction);
+	label_t->setWordWrapMode(QTextOption::NoWrap);
+	label_t->setFrameShape(QFrame::NoFrame);
+	label_t->move(point.x()+12, point.y()+32);
+	label_t->resize(90, size.height()-32);
+
+	QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent);
+	paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
+	paragraph->setWordWrapMode(QTextOption::NoWrap);
+	paragraph->setFrameShape(QFrame::NoFrame);
+	paragraph->move(point.x()+102, point.y()+32);
+	paragraph->resize(size.width()-102, size.height()-32);
+	return paragraph;
+}
+
+/* As far as I can tell, this is identical to the way Taiga implements it.
+   Kind of cool, I didn't even look into the source code for it :p */
+QPlainTextEdit* UiUtils::CreateSelectableTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) {
+	CreateTextHeader(parent, title, point, size);
+
+	QPlainTextEdit* text_edit = new QPlainTextEdit(data, parent);
+	text_edit->setReadOnly(true);
+	text_edit->setFrameShape(QFrame::NoFrame);
+	text_edit->move(point.x()+12, point.y()+32);
+	text_edit->resize(size.width()-12, size.height()-32);
+	return text_edit;
+}