mirror of
https://github.com/YACReader/yacreader
synced 2026-03-01 10:22:58 -05:00
Initial implementation of theming
This commit is contained in:
@ -13,7 +13,6 @@ HEADERS += \
|
||||
$$PWD/yacreader_spin_slider_widget.h \
|
||||
$$PWD/yacreader_tool_bar_stretch.h \
|
||||
$$PWD/yacreader_titled_toolbar.h \
|
||||
$$PWD/yacreader_deleting_progress.h \
|
||||
$$PWD/yacreader_table_view.h \
|
||||
$$PWD/yacreader_sidebar.h \
|
||||
$$PWD/yacreader_library_list_widget.h \
|
||||
@ -38,7 +37,6 @@ SOURCES += \
|
||||
$$PWD/yacreader_spin_slider_widget.cpp \
|
||||
$$PWD/yacreader_tool_bar_stretch.cpp \
|
||||
$$PWD/yacreader_titled_toolbar.cpp \
|
||||
$$PWD/yacreader_deleting_progress.cpp \
|
||||
$$PWD/yacreader_table_view.cpp \
|
||||
$$PWD/yacreader_sidebar.cpp \
|
||||
$$PWD/yacreader_library_list_widget.cpp \
|
||||
|
||||
@ -9,6 +9,12 @@ YACReader::RoundedCornersDialog::RoundedCornersDialog(QWidget *parent)
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
}
|
||||
|
||||
void YACReader::RoundedCornersDialog::setBackgroundColor(const QColor &color)
|
||||
{
|
||||
m_backgroundColor = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void YACReader::RoundedCornersDialog::paintEvent(QPaintEvent *)
|
||||
{
|
||||
qreal radius = 14.0; // desired radius in absolute pixels
|
||||
@ -26,7 +32,7 @@ void YACReader::RoundedCornersDialog::paintEvent(QPaintEvent *)
|
||||
|
||||
// Set the brush from palette role.
|
||||
// p.setBrush(palette().brush(backgroundRole()));
|
||||
p.setBrush(QBrush(QColor(255, 255, 255))); // TODO: the rest of the colors are hardcoded
|
||||
p.setBrush(QBrush(m_backgroundColor));
|
||||
// Got radius? Otherwise draw a quicker rect.
|
||||
if (radius > 0.0)
|
||||
p.drawRoundedRect(rect, radius, radius, Qt::AbsoluteSize);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#ifndef ROUNDEDCORNERSDIALOG_H
|
||||
#define ROUNDEDCORNERSDIALOG_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QDialog>
|
||||
|
||||
namespace YACReader {
|
||||
@ -12,6 +13,10 @@ public:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void setBackgroundColor(const QColor &color);
|
||||
|
||||
private:
|
||||
QColor m_backgroundColor { 255, 255, 255 };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -22,114 +22,121 @@ YACReader::WhatsNewDialog::WhatsNewDialog(QWidget *parent)
|
||||
content->setStyleSheet("background-color:transparent;"
|
||||
"border:none;");
|
||||
|
||||
auto headerImageLabel = new QLabel();
|
||||
QPixmap headerImage(":/images/whats_new/whatsnew_header.svg");
|
||||
headerImageLabel->setPixmap(headerImage);
|
||||
headerImageLabel->setFixedSize(headerImage.size());
|
||||
headerImageLabel = new QLabel();
|
||||
|
||||
auto headerLabel = new QLabel();
|
||||
headerLabel = new QLabel();
|
||||
headerLabel->setText("What's New in\nYACReader");
|
||||
QFont headerLabelFont("Arial", 34, QFont::ExtraBold);
|
||||
headerLabel->setFont(headerLabelFont);
|
||||
headerLabel->setAlignment(Qt::AlignCenter);
|
||||
headerLabel->setStyleSheet("padding: 18px 0 0 0;"
|
||||
"background-color:transparent;"
|
||||
"color:#0A0A0A;");
|
||||
|
||||
auto versionLabel = new QLabel();
|
||||
versionLabel = new QLabel();
|
||||
versionLabel->setText(VERSION);
|
||||
QFont versionLabelFont("Arial", 12, QFont::Normal);
|
||||
versionLabel->setFont(versionLabelFont);
|
||||
versionLabel->setAlignment(Qt::AlignCenter);
|
||||
versionLabel->setStyleSheet("padding:0 0 0 0;"
|
||||
"background-color:transparent;"
|
||||
"color:#858585;");
|
||||
|
||||
auto text = new QLabel();
|
||||
text->setText("This version brings exciting new features, improved functionality, enhanced customization options, bug fixes, and performance improvements across all apps: <br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">YACReader</span><br/>"
|
||||
" • Don't use scroll animations on macOS by default, where hdpi scroll is most likely to be used<br/>"
|
||||
" • New toolbar on macOS<br/>"
|
||||
" • New mouse modes to turn pages - you can setup the app to use the left/right buttons to turn pages directly or click on the left/right part of the screen to turn pages<br/>"
|
||||
" • Fix current page/time label content when the content is too long. (new in 9.16.3)<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">YACReaderLibrary</span><br/>"
|
||||
" • Improve flexibility of the open comic in third party app setting so more complex commands can be used, e.g. `open -a \"/Applications/My Reader.app\" \"{comic_file_path}\"`<br/>"
|
||||
" • Fix setting the comic rating in the table view<br/>"
|
||||
" • Log libraries validation when the app starts<br/>"
|
||||
" • New toolbar on macOS<br/>"
|
||||
" • New setting in Comic Vine scraper to force exact volume matches<br/>"
|
||||
" • Better default search query in the Comic Vine scraper<br/>"
|
||||
" • Improved navigation in Comic Vine scraper, including keeping the current query around to make edits and refined searches easier<br/>"
|
||||
" • Add support for custom covers for any folder using the context menu<br/>"
|
||||
" • The edit cover buttons now support looping through pages, going forward from the last returns to the first, and going backward from the first jumps to the last<br/>"
|
||||
" • Add support for custom covers for comics using the edit metadata dialog, you can use a pick file button or drag&drop an image into the cover view in the dialog<br/>"
|
||||
" • Covers can be set in bulk for various comics at once<br/>"
|
||||
" • New button to reset to the default cover of a comic<br/>"
|
||||
" • Support for storing the new image filters from iOS and Android apps<br/>"
|
||||
" • Fixed cover loading in Comic Vine scraper (new in 9.16.1)<br/>"
|
||||
" • Added a customizable User Agent string to use it with Comic Vine. It can be set in YACReaderLibrary.ini in the [ComicVine] section using the COMIC_VINE_USER_AGENT key (new in 9.16.2)<br/>"
|
||||
" • Prevent crash when opening the folders context menu if a folder is not selected. (new in 9.16.2)<br/>"
|
||||
" • Fix crash when using the `Set type` menu on libraries. (new in 9.16.2)<br/>"
|
||||
" • Fix table view last section stretch. Before it was only working randomly. (new in 9.16.3)<br/>"
|
||||
" • Fix empty table view caused by wront state being saved. You'll need to reconfigure the table view headers to your liking after this udpate. (new in 9.16.3)<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">YACReaderLibraryServer</span><br/>"
|
||||
" • Log libraries validation when the app starts<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">All apps</span><br/>"
|
||||
" • PDF support has been updated in all Windows apps<br/>"
|
||||
"<br/>"
|
||||
"I hope you enjoy the new update. Please, if you like YACReader consider to become a patron in <a href=\"https://www.patreon.com/yacreader\" style=\"color:#E8B800;\">Patreon</a> "
|
||||
"or donate some money using <a href=\"https://www.paypal.com/donate?business=5TAMNQCDDMVP8&item_name=Support+YACReader\" style=\"color:#E8B800;\">Pay-Pal</a> and help keeping the project alive. "
|
||||
"Remember that there is an iOS version available in the <a href=\"https://apps.apple.com/app/id635717885\" style=\"color:#E8B800;\">Apple App Store</a>, "
|
||||
"and there is a brand new app for Android that you can get on the <a href=\"https://play.google.com/store/apps/details?id=com.yacreader.yacreader\" style=\"color:#E8B800;\">Google Play Store</a>.");
|
||||
textLabel = new QLabel();
|
||||
htmlTemplate = "This version brings exciting new features, improved functionality, enhanced customization options, bug fixes, and performance improvements across all apps: <br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">YACReader</span><br/>"
|
||||
" • Don't use scroll animations on macOS by default, where hdpi scroll is most likely to be used<br/>"
|
||||
" • New toolbar on macOS<br/>"
|
||||
" • New mouse modes to turn pages - you can setup the app to use the left/right buttons to turn pages directly or click on the left/right part of the screen to turn pages<br/>"
|
||||
" • Fix current page/time label content when the content is too long. (new in 9.16.3)<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">YACReaderLibrary</span><br/>"
|
||||
" • Improve flexibility of the open comic in third party app setting so more complex commands can be used, e.g. `open -a \"/Applications/My Reader.app\" \"{comic_file_path}\"`<br/>"
|
||||
" • Fix setting the comic rating in the table view<br/>"
|
||||
" • Log libraries validation when the app starts<br/>"
|
||||
" • New toolbar on macOS<br/>"
|
||||
" • New setting in Comic Vine scraper to force exact volume matches<br/>"
|
||||
" • Better default search query in the Comic Vine scraper<br/>"
|
||||
" • Improved navigation in Comic Vine scraper, including keeping the current query around to make edits and refined searches easier<br/>"
|
||||
" • Add support for custom covers for any folder using the context menu<br/>"
|
||||
" • The edit cover buttons now support looping through pages, going forward from the last returns to the first, and going backward from the first jumps to the last<br/>"
|
||||
" • Add support for custom covers for comics using the edit metadata dialog, you can use a pick file button or drag&drop an image into the cover view in the dialog<br/>"
|
||||
" • Covers can be set in bulk for various comics at once<br/>"
|
||||
" • New button to reset to the default cover of a comic<br/>"
|
||||
" • Support for storing the new image filters from iOS and Android apps<br/>"
|
||||
" • Fixed cover loading in Comic Vine scraper (new in 9.16.1)<br/>"
|
||||
" • Added a customizable User Agent string to use it with Comic Vine. It can be set in YACReaderLibrary.ini in the [ComicVine] section using the COMIC_VINE_USER_AGENT key (new in 9.16.2)<br/>"
|
||||
" • Prevent crash when opening the folders context menu if a folder is not selected. (new in 9.16.2)<br/>"
|
||||
" • Fix crash when using the `Set type` menu on libraries. (new in 9.16.2)<br/>"
|
||||
" • Fix table view last section stretch. Before it was only working randomly. (new in 9.16.3)<br/>"
|
||||
" • Fix empty table view caused by wront state being saved. You'll need to reconfigure the table view headers to your liking after this udpate. (new in 9.16.3)<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">YACReaderLibraryServer</span><br/>"
|
||||
" • Log libraries validation when the app starts<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">All apps</span><br/>"
|
||||
" • PDF support has been updated in all Windows apps<br/>"
|
||||
"<br/>"
|
||||
"I hope you enjoy the new update. Please, if you like YACReader consider to become a patron in <a href=\"https://www.patreon.com/yacreader\" style=\"color:%1;\">Patreon</a> "
|
||||
"or donate some money using <a href=\"https://www.paypal.com/donate?business=5TAMNQCDDMVP8&item_name=Support+YACReader\" style=\"color:%1;\">Pay-Pal</a> and help keeping the project alive. "
|
||||
"Remember that there is an iOS version available in the <a href=\"https://apps.apple.com/app/id635717885\" style=\"color:%1;\">Apple App Store</a>, "
|
||||
"and there is a brand new app for Android that you can get on the <a href=\"https://play.google.com/store/apps/details?id=com.yacreader.yacreader\" style=\"color:%1;\">Google Play Store</a>.";
|
||||
|
||||
QFont textLabelFont("Arial", 15, QFont::Light);
|
||||
text->setFont(textLabelFont);
|
||||
text->setStyleSheet("padding:51px;"
|
||||
"background-color:transparent;"
|
||||
"color:#0A0A0A;");
|
||||
text->setWordWrap(true);
|
||||
text->setOpenExternalLinks(true);
|
||||
textLabel->setFont(textLabelFont);
|
||||
textLabel->setWordWrap(true);
|
||||
textLabel->setOpenExternalLinks(true);
|
||||
|
||||
contentLayout->addItem(new QSpacerItem(0, 50), 0, 0);
|
||||
contentLayout->addWidget(headerImageLabel, 1, 0, Qt::AlignTop | Qt::AlignHCenter);
|
||||
contentLayout->addWidget(headerLabel, 1, 0, Qt::AlignTop | Qt::AlignHCenter);
|
||||
contentLayout->addWidget(versionLabel, 2, 0, Qt::AlignTop | Qt::AlignHCenter);
|
||||
contentLayout->addWidget(text, 3, 0, Qt::AlignTop);
|
||||
contentLayout->addWidget(textLabel, 3, 0, Qt::AlignTop);
|
||||
contentLayout->setRowStretch(3, 1);
|
||||
content->setLayout(contentLayout);
|
||||
|
||||
mainLayout->addWidget(scrollArea);
|
||||
|
||||
// containerLayout->addWidget(content);
|
||||
scrollArea->setWidget(content);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
|
||||
this->setLayout(mainLayout);
|
||||
|
||||
auto closeButton = new QPushButton(this);
|
||||
closeButton = new QPushButton(this);
|
||||
closeButton->setFlat(true);
|
||||
closeButton->setStyleSheet("background-color:transparent;");
|
||||
auto closeIcon = QPixmap(":/images/custom_dialog/custom_close_button.svg");
|
||||
if (!closeIcon.isNull()) {
|
||||
closeButton->setIcon(QPixmap(":/images/custom_dialog/custom_close_button.svg"));
|
||||
closeButton->setIconSize(QSize(44, 44));
|
||||
closeButton->setFixedSize(44, 44);
|
||||
closeButton->move(656, 20);
|
||||
} else {
|
||||
closeButton->setText(tr("Close"));
|
||||
auto font = closeButton->font();
|
||||
font.setPointSize(16);
|
||||
closeButton->setFont(font);
|
||||
closeButton->move(616, 20);
|
||||
}
|
||||
closeButton->setIconSize(QSize(44, 44));
|
||||
closeButton->setFixedSize(44, 44);
|
||||
closeButton->move(656, 20);
|
||||
|
||||
scrollArea->setFixedSize(720, 640);
|
||||
setFixedSize(720, 640);
|
||||
setModal(true);
|
||||
|
||||
connect(closeButton, &QPushButton::clicked, this, &QDialog::close);
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void YACReader::WhatsNewDialog::applyTheme(const Theme &theme)
|
||||
{
|
||||
auto whatsNewTheme = theme.whatsNewDialog;
|
||||
|
||||
setBackgroundColor(whatsNewTheme.backgroundColor);
|
||||
|
||||
headerImageLabel->setPixmap(whatsNewTheme.headerDecoration);
|
||||
headerImageLabel->setFixedSize(whatsNewTheme.headerDecoration.size());
|
||||
|
||||
headerLabel->setStyleSheet(QString("padding: 18px 0 0 0;"
|
||||
"background-color:transparent;"
|
||||
"color:%1;")
|
||||
.arg(whatsNewTheme.headerTextColor.name()));
|
||||
|
||||
versionLabel->setStyleSheet(QString("padding:0 0 0 0;"
|
||||
"background-color:transparent;"
|
||||
"color:%1;")
|
||||
.arg(whatsNewTheme.versionTextColor.name()));
|
||||
|
||||
textLabel->setStyleSheet(QString("padding:51px;"
|
||||
"background-color:transparent;"
|
||||
"color:%1;")
|
||||
.arg(whatsNewTheme.contentTextColor.name()));
|
||||
textLabel->setText(htmlTemplate.arg(whatsNewTheme.linkColor.name()));
|
||||
|
||||
closeButton->setIcon(whatsNewTheme.closeButtonIcon);
|
||||
}
|
||||
|
||||
@ -2,15 +2,29 @@
|
||||
#define WHATSNEWDIALOG_H
|
||||
|
||||
#include "rounded_corners_dialog.h"
|
||||
#include <QObject>
|
||||
#include "themable.h"
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
|
||||
namespace YACReader {
|
||||
|
||||
class WhatsNewDialog : public RoundedCornersDialog
|
||||
class WhatsNewDialog : public RoundedCornersDialog, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WhatsNewDialog(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void applyTheme(const Theme &theme) override;
|
||||
|
||||
private:
|
||||
QLabel *headerImageLabel;
|
||||
QLabel *headerLabel;
|
||||
QLabel *versionLabel;
|
||||
QLabel *textLabel;
|
||||
QPushButton *closeButton;
|
||||
QString htmlTemplate;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,105 +0,0 @@
|
||||
#include "yacreader_deleting_progress.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
|
||||
YACReaderDeletingProgress::YACReaderDeletingProgress(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *contentLayout = new QVBoxLayout(this);
|
||||
|
||||
QLabel *iconLabel = new QLabel();
|
||||
QPixmap icon(":/images/deleting_progress/icon.png");
|
||||
iconLabel->setPixmap(icon);
|
||||
iconLabel->setStyleSheet("QLabel {padding:0px; margin:0px;}");
|
||||
|
||||
textMessage = new QLabel(tr("Please wait, deleting in progress..."));
|
||||
|
||||
textMessage->setStyleSheet("QLabel {color:#ABABAB; padding:0 0 0 0px; margin:0px; font-size:18px; font-weight:bold;}");
|
||||
|
||||
QProgressBar *progressBar = new QProgressBar();
|
||||
|
||||
progressBar->setTextVisible(false);
|
||||
progressBar->setFixedHeight(6);
|
||||
progressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
progressBar->setRange(0, 10);
|
||||
progressBar->setValue(5);
|
||||
progressBar->setStyleSheet(
|
||||
"QProgressBar { border: none; border-radius: 3px; background: #ABABAB; margin:0; margin-left:16; margin-right:16px;}"
|
||||
"QProgressBar::chunk {background-color: #FFC745; border: none; border-radius: 3px;}");
|
||||
|
||||
QPushButton *button = new QPushButton(tr("cancel"));
|
||||
|
||||
button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
|
||||
contentLayout->addSpacing(16);
|
||||
contentLayout->addWidget(iconLabel, 0, Qt::AlignHCenter);
|
||||
contentLayout->addSpacing(11);
|
||||
contentLayout->addWidget(textMessage, 0, Qt::AlignHCenter);
|
||||
contentLayout->addSpacing(13);
|
||||
contentLayout->addWidget(progressBar);
|
||||
contentLayout->addSpacing(13);
|
||||
contentLayout->addWidget(button, 0, Qt::AlignHCenter);
|
||||
contentLayout->addSpacing(18);
|
||||
|
||||
contentLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
setLayout(contentLayout);
|
||||
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
|
||||
resize(sizeHint());
|
||||
}
|
||||
|
||||
void YACReaderDeletingProgress::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
int borderTop, borderRight, borderBottom, borderLeft;
|
||||
|
||||
QPixmap pL(":/images/deleting_progress/imgTopLeft.png");
|
||||
QPixmap pM(":/images/deleting_progress/imgTopMiddle.png");
|
||||
QPixmap pR(":/images/deleting_progress/imgTopRight.png");
|
||||
|
||||
QPixmap pLM(":/images/deleting_progress/imgLeftMiddle.png");
|
||||
|
||||
QPixmap pRM(":/images/deleting_progress/imgRightMiddle.png");
|
||||
|
||||
QPixmap pBL(":/images/deleting_progress/imgBottomLeft.png");
|
||||
QPixmap pBM(":/images/deleting_progress/imgBottomMiddle.png");
|
||||
QPixmap pBR(":/images/deleting_progress/imgBottomRight.png");
|
||||
|
||||
borderTop = pL.height();
|
||||
borderRight = pRM.width();
|
||||
borderBottom = pBM.height();
|
||||
borderLeft = pLM.width();
|
||||
|
||||
int width = this->width() - borderRight - borderLeft;
|
||||
int height = this->height() - borderTop - borderBottom;
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
// corners
|
||||
painter.drawPixmap(0, 0, pL);
|
||||
painter.drawPixmap(this->width() - borderRight, 0, pR);
|
||||
painter.drawPixmap(0, this->height() - pBL.height(), pBL);
|
||||
painter.drawPixmap(this->width() - pBR.width(), this->height() - borderBottom, pBR);
|
||||
|
||||
// middle
|
||||
painter.drawPixmap(borderRight, 0, width, borderTop, pM);
|
||||
painter.drawPixmap(0, borderTop, borderLeft, height, pLM);
|
||||
painter.drawPixmap(width + borderLeft, borderTop, borderRight, height, pRM);
|
||||
painter.drawPixmap(pBR.width(), height + borderTop, this->width() - pBR.width() - pBL.width(), pBR.height(), pBM);
|
||||
|
||||
// center
|
||||
painter.fillRect(borderLeft, borderTop, width, height, QColor("#FAFAFA"));
|
||||
|
||||
QWidget::paintEvent(event);
|
||||
}
|
||||
|
||||
QSize YACReaderDeletingProgress::sizeHint() const
|
||||
{
|
||||
return QSize(textMessage->sizeHint().width() + 120, 185);
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
#ifndef YACREADER_DELETING_PROGRESS_H
|
||||
#define YACREADER_DELETING_PROGRESS_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLabel;
|
||||
|
||||
class YACReaderDeletingProgress : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit YACReaderDeletingProgress(QWidget *parent = 0);
|
||||
QSize sizeHint() const;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
QLabel *textMessage;
|
||||
};
|
||||
|
||||
#endif // YACREADER_DELETING_PROGRESS_H
|
||||
@ -19,20 +19,15 @@ YACReaderLibraryItemWidget::YACReaderLibraryItemWidget(QString n /*ame*/, QStrin
|
||||
|
||||
// installEventFilter(this);
|
||||
|
||||
QPixmap iconPixmap = hdpiPixmap(addExtensionToIconPath(":/images/sidebar/libraryIcon"), QSize(16, 16));
|
||||
icon = new QLabel(this);
|
||||
icon->setPixmap(iconPixmap);
|
||||
|
||||
nameLabel = new QLabel(name, this);
|
||||
|
||||
options = new QToolButton(this);
|
||||
|
||||
QPixmap iconOptionsPixmap = hdpiPixmap(":/images/sidebar/libraryOptions.svg", QSize(8, 8));
|
||||
iconOptionsPixmap.setDevicePixelRatio(devicePixelRatioF());
|
||||
QLabel *helperLabel = new QLabel(options);
|
||||
helperLabel->move(4, 3);
|
||||
helperLabel->setFixedSize(14, 14);
|
||||
helperLabel->setPixmap(iconOptionsPixmap);
|
||||
optionsIconLabel = new QLabel(options);
|
||||
optionsIconLabel->move(4, 3);
|
||||
optionsIconLabel->setFixedSize(14, 14);
|
||||
|
||||
options->setHidden(true);
|
||||
options->setIconSize(QSize(18, 18));
|
||||
@ -57,10 +52,6 @@ YACReaderLibraryItemWidget::YACReaderLibraryItemWidget(QString n /*ame*/, QStrin
|
||||
mainLayout->addWidget(down);*/
|
||||
|
||||
setLayout(mainLayout);
|
||||
#ifndef Y_MAC_UI
|
||||
QString styleSheet = "background-color:transparent; color:#DDDFDF;";
|
||||
setStyleSheet(styleSheet);
|
||||
#endif
|
||||
|
||||
QString iconStyleSheet = "QLabel {padding:0 0 0 24px; margin:0px}";
|
||||
icon->setStyleSheet(iconStyleSheet);
|
||||
@ -70,6 +61,35 @@ YACReaderLibraryItemWidget::YACReaderLibraryItemWidget(QString n /*ame*/, QStrin
|
||||
|
||||
setMinimumHeight(20);
|
||||
setAttribute(Qt::WA_StyledBackground, true);
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void YACReaderLibraryItemWidget::applyTheme(const Theme &theme)
|
||||
{
|
||||
const auto &icons = theme.sidebarIcons;
|
||||
const auto &li = theme.libraryItem;
|
||||
|
||||
// Update icon based on current selection state
|
||||
QIcon iconToUse = isSelected ? li.libraryIconSelected : icons.libraryIcon;
|
||||
icon->setPixmap(iconToUse.pixmap(16, 16));
|
||||
|
||||
// Update options icon (uses libraryItem theme since it's only shown when selected)
|
||||
QPixmap optionsPixmap = li.libraryOptionsIcon.pixmap(8, 8);
|
||||
optionsPixmap.setDevicePixelRatio(devicePixelRatioF());
|
||||
optionsIconLabel->setPixmap(optionsPixmap);
|
||||
|
||||
// Update widget styling based on selection state
|
||||
if (isSelected) {
|
||||
QString styleSheet = QString("color: %1; background-color: %2; font-weight:bold;")
|
||||
.arg(li.selectedTextColor.name())
|
||||
.arg(li.selectedBackgroundColor.name());
|
||||
setStyleSheet(styleSheet);
|
||||
} else {
|
||||
QString styleSheet = QString("background-color:transparent; color: %1;")
|
||||
.arg(li.textColor.name());
|
||||
setStyleSheet(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
void YACReaderLibraryItemWidget::showUpDownButtons(bool show)
|
||||
@ -117,17 +137,11 @@ bool YACReaderLibraryItemWidget::eventFilter(QObject *object, QEvent *event){
|
||||
|
||||
void YACReaderLibraryItemWidget::deselect()
|
||||
{
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
QString styleSheet = "background-color:transparent;";
|
||||
QString styleSheet = QString("background-color:transparent; color: %1;")
|
||||
.arg(theme.libraryItem.textColor.name());
|
||||
setStyleSheet(styleSheet);
|
||||
#else
|
||||
QString styleSheet = "background-color:transparent; color:#DDDFDF;";
|
||||
setStyleSheet(styleSheet);
|
||||
#endif
|
||||
|
||||
QPixmap iconPixmap = hdpiPixmap(addExtensionToIconPath(":/images/sidebar/libraryIcon"), QSize(16, 16));
|
||||
icon->setPixmap(iconPixmap);
|
||||
icon->setPixmap(theme.sidebarIcons.libraryIcon.pixmap(16, 16));
|
||||
|
||||
/*up->setHidden(true);
|
||||
down->setHidden(true);*/
|
||||
@ -138,18 +152,15 @@ void YACReaderLibraryItemWidget::deselect()
|
||||
|
||||
void YACReaderLibraryItemWidget::select()
|
||||
{
|
||||
#ifdef Y_MAC_UI
|
||||
// QString styleSheet ="color: white; background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6BAFE4, stop: 1 #3984D2); border-top: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #5EA3DF, stop: 1 #73B8EA); border-left:none;border-right:none;border-bottom:1px solid #3577C2;";
|
||||
QString styleSheet = "color: white; background-color:#91c4f4; border-bottom:1px solid #91c4f4;";
|
||||
#else
|
||||
QString styleSheet = "color: white; background-color:#2E2E2E; font-weight:bold;";
|
||||
#endif
|
||||
const auto &li = theme.libraryItem;
|
||||
QString styleSheet = QString("color: %1; background-color: %2; font-weight:bold;")
|
||||
.arg(li.selectedTextColor.name())
|
||||
.arg(li.selectedBackgroundColor.name());
|
||||
setStyleSheet(styleSheet);
|
||||
|
||||
options->setHidden(false);
|
||||
|
||||
QPixmap iconPixmap = hdpiPixmap(":/images/sidebar/libraryIconSelected.svg", QSize(16, 16));
|
||||
icon->setPixmap(iconPixmap);
|
||||
icon->setPixmap(theme.libraryItem.libraryIconSelected.pixmap(16, 16));
|
||||
|
||||
isSelected = true;
|
||||
}
|
||||
|
||||
@ -2,13 +2,16 @@
|
||||
#define YACREADER_LIBRARY_ITEM_WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "themable.h"
|
||||
|
||||
class QLabel;
|
||||
class QToolButton;
|
||||
class QMouseEvent;
|
||||
class QEvent;
|
||||
|
||||
class YACReaderLibraryItemWidget : public QWidget
|
||||
class YACReaderLibraryItemWidget : public QWidget, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -32,12 +35,16 @@ public slots:
|
||||
private:
|
||||
QLabel *icon;
|
||||
QLabel *nameLabel;
|
||||
QLabel *optionsIconLabel;
|
||||
|
||||
QToolButton *options;
|
||||
QToolButton *up;
|
||||
QToolButton *down;
|
||||
|
||||
bool isSelected;
|
||||
|
||||
protected:
|
||||
void applyTheme(const Theme &theme) override;
|
||||
};
|
||||
|
||||
#endif // YACREADER_LIBRARY_ITEM_WIDGET_H
|
||||
|
||||
@ -1,92 +1,6 @@
|
||||
#ifndef YACREADER_MACOSX_TOOLBAR_H
|
||||
#define YACREADER_MACOSX_TOOLBAR_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QMacToolBar>
|
||||
#include <QtWidgets>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "yacreader_global.h"
|
||||
|
||||
// Wrapper for NSTextField
|
||||
class YACReaderMacOSXSearchLineEdit : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
YACReaderMacOSXSearchLineEdit();
|
||||
void setFocus(Qt::FocusReason reason);
|
||||
void *getNSTextField();
|
||||
|
||||
public slots:
|
||||
QString text();
|
||||
void clear();
|
||||
void clearText(); // no signal emited
|
||||
void setDisabled(bool disabled);
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
void *nstextfield;
|
||||
|
||||
signals:
|
||||
// convenience signal for YACReaderLibrary search edit
|
||||
void filterChanged(QString);
|
||||
};
|
||||
|
||||
class MacToolBarItemWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MacToolBarItemWrapper(QAction *action, QMacToolBarItem *toolbaritem);
|
||||
|
||||
public slots:
|
||||
void actionToggled(bool toogled);
|
||||
|
||||
private:
|
||||
QAction *action;
|
||||
QMacToolBarItem *toolbaritem;
|
||||
|
||||
void updateIcon(bool checked);
|
||||
};
|
||||
|
||||
class YACReaderMacOSXToolbar : public QMacToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit YACReaderMacOSXToolbar(QObject *parent = 0);
|
||||
void addAction(QAction *action);
|
||||
void addDropDownItem(const QList<QAction *> &actions, const QAction *defaultAction = 0);
|
||||
void addSpace(int size); // size in points
|
||||
void addSeparator();
|
||||
void addStretch();
|
||||
void addWidget(QWidget *widget);
|
||||
void show();
|
||||
void hide();
|
||||
QMap<QString, QAction *> actions;
|
||||
|
||||
// hacks everywhere
|
||||
// convenience method for YACReaderLibrary search edit
|
||||
YACReaderMacOSXSearchLineEdit *addSearchEdit();
|
||||
// convenience method for showing the fit to width slider in MacOSX
|
||||
QAction *addFitToWidthSlider(QAction *attachToAction);
|
||||
|
||||
// convenience method for switching the icon of the view selector
|
||||
void updateViewSelectorIcon(const QIcon &icon);
|
||||
|
||||
void attachToWindow(QMainWindow *window);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
NSToolbar *nativeToolBar;
|
||||
void *delegate;
|
||||
bool yosemite;
|
||||
QMacToolBarItem *viewSelector;
|
||||
};
|
||||
#else
|
||||
|
||||
#ifdef YACREADER_LIBRARY
|
||||
|
||||
#include "yacreader_main_toolbar.h"
|
||||
@ -149,6 +63,4 @@ public slots:
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // YACREADER_MACOSX_TOOLBAR_H
|
||||
|
||||
@ -1,403 +1,8 @@
|
||||
#include "yacreader_macosx_toolbar.h"
|
||||
#include "QtWidgets/qmainwindow.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QtWidgets>
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QWidget>
|
||||
#include <QMacNativeWidget>
|
||||
#include <qmacfunctions.h>
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
#include <QsLog.h>
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "shortcuts_manager.h"
|
||||
|
||||
//----------------------------
|
||||
// A custom items separator for NSToolbar
|
||||
@interface CustomSeparator : NSView
|
||||
|
||||
@end
|
||||
|
||||
@implementation CustomSeparator
|
||||
|
||||
- (void)drawRect:(NSRect)rect
|
||||
{
|
||||
[[NSColor colorWithDeviceRed:0.5 green:0.5 blue:0.5 alpha:1] setFill];
|
||||
NSRectFill(rect);
|
||||
[super drawRect:rect];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
//----------------------------
|
||||
// Toolbar delegate, needed for allow disabled/enabled items
|
||||
@interface MyToolbarDelegate : NSObject <NSToolbarDelegate> {
|
||||
@public
|
||||
YACReaderMacOSXToolbar *mytoolbar;
|
||||
}
|
||||
|
||||
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdent willBeInsertedIntoToolbar:(BOOL)willBeInserted;
|
||||
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar;
|
||||
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar;
|
||||
//- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar;
|
||||
- (IBAction)itemClicked:(id)sender;
|
||||
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem;
|
||||
@end
|
||||
|
||||
@implementation MyToolbarDelegate
|
||||
|
||||
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
Q_UNUSED(toolbar);
|
||||
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
|
||||
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||
foreach (const QMacToolBarItem *item, items) {
|
||||
[array addObject:item->nativeToolBarItem().itemIdentifier];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
Q_UNUSED(toolbar);
|
||||
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
|
||||
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||
foreach (const QMacToolBarItem *item, items) {
|
||||
[array addObject:item->nativeToolBarItem().itemIdentifier];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/*
|
||||
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
|
||||
{
|
||||
Q_UNUSED(toolbar);
|
||||
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
|
||||
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||
foreach (const QMacToolBarItem * item, items) {
|
||||
[array addObject : item->nativeToolBarItem().itemIdentifier];
|
||||
}
|
||||
return array;
|
||||
//NSMutableArray *array = toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, true);
|
||||
//[array addObjectsFromArray:toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, true)];
|
||||
//return array;
|
||||
}*/
|
||||
|
||||
- (IBAction)itemClicked:(id)sender
|
||||
{
|
||||
if ([sender respondsToSelector:@selector(itemIdentifier)]) {
|
||||
NSToolbarItem *item = reinterpret_cast<NSToolbarItem *>(sender);
|
||||
|
||||
QString identifier = QString::fromNSString([item itemIdentifier]);
|
||||
QMacToolBarItem *toolButton = reinterpret_cast<QMacToolBarItem *>(identifier.toULongLong());
|
||||
Q_EMIT toolButton->activated();
|
||||
}
|
||||
}
|
||||
|
||||
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)willBeInserted
|
||||
{
|
||||
Q_UNUSED(toolbar);
|
||||
Q_UNUSED(willBeInserted);
|
||||
QList<QMacToolBarItem *> items = mytoolbar->items();
|
||||
|
||||
foreach (const QMacToolBarItem *item, items) {
|
||||
NSToolbarItem *toolbarItem = item->nativeToolBarItem();
|
||||
if ([toolbarItem.itemIdentifier isEqual:itemIdentifier]) {
|
||||
|
||||
[toolbarItem setTarget:self];
|
||||
[toolbarItem setAction:@selector(itemClicked:)];
|
||||
|
||||
return toolbarItem;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
|
||||
{
|
||||
QString identifier = QString::fromNSString(theItem.itemIdentifier);
|
||||
|
||||
if (mytoolbar->actions.contains(identifier)) {
|
||||
return mytoolbar->actions.value(identifier)->isEnabled();
|
||||
} else
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
//----------------------------
|
||||
// detect changes in native text field
|
||||
// TODO implement validation and auto completion
|
||||
@interface MyTextFieldDelegate : NSObject <NSTextFieldDelegate> {
|
||||
@public
|
||||
YACReaderMacOSXSearchLineEdit *mylineedit;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MyTextFieldDelegate
|
||||
|
||||
- (void)controlTextDidChange:(NSNotification *)notification
|
||||
{
|
||||
NSTextField *textField = [notification object];
|
||||
NSLog(@"%@", [textField stringValue]);
|
||||
Q_EMIT mylineedit->filterChanged(QString::fromNSString([textField stringValue]));
|
||||
}
|
||||
|
||||
@end
|
||||
//----------------------------
|
||||
|
||||
YACReaderMacOSXToolbar::YACReaderMacOSXToolbar(QObject *parent)
|
||||
: viewSelector(0)
|
||||
{
|
||||
// setup native toolbar
|
||||
nativeToolBar = nativeToolbar();
|
||||
[nativeToolBar setDisplayMode:NSToolbarDisplayModeIconOnly];
|
||||
[nativeToolBar setAllowsUserCustomization:NO];
|
||||
|
||||
delegate = [[MyToolbarDelegate alloc] init];
|
||||
((MyToolbarDelegate *)delegate)->mytoolbar = this;
|
||||
[nativeToolBar setDelegate:(MyToolbarDelegate *)delegate];
|
||||
|
||||
#ifdef YACREADER_LIBRARY
|
||||
NSWindow *nswindow = (NSWindow *)qApp->platformNativeInterface()->nativeResourceForWindow("nswindow", ((QMainWindow *)parent)->windowHandle());
|
||||
if ([nswindow respondsToSelector:@selector(setTitleVisibility:)]) {
|
||||
yosemite = true;
|
||||
// TODO yosemite new constants are not found in compilation time
|
||||
[nswindow setTitleVisibility:NSWindowTitleHidden];
|
||||
// TODO NSFullSizeContentViewWindowMask produces an offset in the windows' content
|
||||
// nswindow.styleMask |= 1 << 15; // NSFullSizeContentViewWindowMask;
|
||||
[nativeToolBar setSizeMode:NSToolbarSizeModeSmall]; // TODO figure out how to load specific images in Yosemite
|
||||
} else {
|
||||
[nativeToolBar setSizeMode:NSToolbarSizeModeSmall];
|
||||
yosemite = false;
|
||||
}
|
||||
#else
|
||||
yosemite = false;
|
||||
[nativeToolBar setAutosavesConfiguration:YES]; // TODO this doesn't work
|
||||
[nativeToolBar setSizeMode:NSToolbarSizeModeSmall];
|
||||
#endif
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::addAction(QAction *action)
|
||||
{
|
||||
QMacToolBarItem *toolBarItem = addItem(action->icon(), action->text());
|
||||
if (action->data().toString() == TOGGLE_COMICS_VIEW_ACTION_YL)
|
||||
viewSelector = toolBarItem;
|
||||
connect(toolBarItem, &QMacToolBarItem::activated, action, [=] { emit action->triggered(); });
|
||||
|
||||
NSToolbarItem *nativeItem = toolBarItem->nativeToolBarItem();
|
||||
actions.insert(QString::fromNSString(nativeItem.itemIdentifier), action);
|
||||
|
||||
MacToolBarItemWrapper *wrapper = new MacToolBarItemWrapper(action, toolBarItem);
|
||||
// wrapper->actionToogled(true);
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::addDropDownItem(const QList<QAction *> &actions, const QAction *defaultAction)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::addSpace(int size)
|
||||
{
|
||||
QMacToolBarItem *toolBarItem = addItem(QIcon(), "");
|
||||
NSToolbarItem *nativeItem = toolBarItem->nativeToolBarItem();
|
||||
|
||||
static const NSRect frameRect = { { 0.0, 0.0 }, { CGFloat(size), 16.0 } };
|
||||
NSView *view = [[NSView alloc] initWithFrame:frameRect];
|
||||
|
||||
[nativeItem setView:view];
|
||||
}
|
||||
|
||||
// reimplemented for convenience
|
||||
void YACReaderMacOSXToolbar::addSeparator()
|
||||
{
|
||||
// QMacToolBar::addSeparator();
|
||||
|
||||
QMacToolBarItem *toolBarItem = addItem(QIcon(), "");
|
||||
NSToolbarItem *nativeItem = toolBarItem->nativeToolBarItem();
|
||||
|
||||
static const NSRect frameRect = { { 0.0, 0.0 }, { 1, 16.0 } };
|
||||
CustomSeparator *view = [[CustomSeparator alloc] initWithFrame:frameRect];
|
||||
|
||||
[nativeItem setView:view];
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::addStretch()
|
||||
{
|
||||
QMacToolBarItem *toolBarItem = addItem(QIcon(), "");
|
||||
toolBarItem->setStandardItem(QMacToolBarItem::FlexibleSpace);
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::addWidget(QWidget *widget)
|
||||
{
|
||||
// TODO fix it
|
||||
/* QMacNativeWidget *nativeWidget = new QMacNativeWidget();
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
layout->addWidget(widget);
|
||||
nativeWidget->setLayout(layout);
|
||||
|
||||
|
||||
NSView *nativeWidgetView = reinterpret_cast<NSView *>(nativeWidget->winId());
|
||||
QMacToolBarItem *toolBarItem = addItem(QIcon(),"");
|
||||
NSToolbarItem * nativeItem = toolBarItem->nativeToolBarItem();
|
||||
[nativeItem setView:nativeWidgetView];*/
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::show()
|
||||
{
|
||||
[nativeToolBar setVisible:YES];
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::hide()
|
||||
{
|
||||
[nativeToolBar setVisible:NO];
|
||||
}
|
||||
|
||||
YACReaderMacOSXSearchLineEdit *YACReaderMacOSXToolbar::addSearchEdit()
|
||||
{
|
||||
QMacToolBarItem *toolBarItem = addItem(QIcon(), "");
|
||||
NSToolbarItem *nativeItem = toolBarItem->nativeToolBarItem();
|
||||
|
||||
YACReaderMacOSXSearchLineEdit *searchEdit = new YACReaderMacOSXSearchLineEdit();
|
||||
|
||||
if (yosemite)
|
||||
[nativeItem setView:(NSTextField *)searchEdit->getNSTextField()];
|
||||
else {
|
||||
static const NSRect searchEditFrameRect = { { 0.0, 0.0 }, { 165, 26.0 } };
|
||||
NSView *view = [[NSView alloc] initWithFrame:searchEditFrameRect];
|
||||
[view addSubview:((NSTextField *)searchEdit->getNSTextField())];
|
||||
[nativeItem setView:view];
|
||||
}
|
||||
|
||||
return searchEdit;
|
||||
}
|
||||
|
||||
// deprecated
|
||||
QAction *YACReaderMacOSXToolbar::addFitToWidthSlider(QAction *attachToAction)
|
||||
{
|
||||
QMacToolBarItem *toolBarItem = addItem(QIcon(":/images/viewer_toolbar/toWidthSlider.png"), "fit to width slider");
|
||||
|
||||
NSToolbarItem *nativeItem = toolBarItem->nativeToolBarItem();
|
||||
actions.insert(QString::fromNSString(nativeItem.itemIdentifier), attachToAction);
|
||||
|
||||
QAction *action = new QAction("", attachToAction->parent());
|
||||
|
||||
connect(toolBarItem, &QMacToolBarItem::activated, action, [=] { emit action->triggered(); });
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::updateViewSelectorIcon(const QIcon &icon)
|
||||
{
|
||||
if (viewSelector)
|
||||
viewSelector->setIcon(icon);
|
||||
}
|
||||
|
||||
void YACReaderMacOSXToolbar::attachToWindow(QMainWindow *window)
|
||||
{
|
||||
QMacToolBar::attachToWindow(window->windowHandle());
|
||||
}
|
||||
|
||||
YACReaderMacOSXSearchLineEdit::YACReaderMacOSXSearchLineEdit()
|
||||
: QObject()
|
||||
{
|
||||
NSRect searchEditFrameRect = { { 0.0, -3.0 }, { 165, 32.0 } };
|
||||
// NSTextField * searchEdit = [[NSTextField alloc] initWithFrame:searchEditFrameRect];
|
||||
|
||||
NSTextField *searchEdit = [[NSSearchField alloc] initWithFrame:searchEditFrameRect];
|
||||
//[searchEdit setBezelStyle:NSTextFieldRoundedBezel];
|
||||
|
||||
[[searchEdit cell] setPlaceholderString:@"type to search"];
|
||||
|
||||
MyTextFieldDelegate *delegate = [[MyTextFieldDelegate alloc] init];
|
||||
delegate->mylineedit = this;
|
||||
[searchEdit setDelegate:delegate];
|
||||
|
||||
nstextfield = searchEdit;
|
||||
}
|
||||
|
||||
void YACReaderMacOSXSearchLineEdit::setFocus(Qt::FocusReason reason)
|
||||
{
|
||||
Q_UNUSED(reason)
|
||||
|
||||
[((NSTextField *)nstextfield) becomeFirstResponder];
|
||||
}
|
||||
|
||||
void *YACReaderMacOSXSearchLineEdit::getNSTextField()
|
||||
{
|
||||
return nstextfield;
|
||||
}
|
||||
|
||||
QString YACReaderMacOSXSearchLineEdit::text()
|
||||
{
|
||||
return QString::fromNSString([((NSTextField *)nstextfield) stringValue]);
|
||||
}
|
||||
|
||||
void YACReaderMacOSXSearchLineEdit::clear()
|
||||
{
|
||||
[((NSTextField *)nstextfield) setStringValue:@""];
|
||||
emit filterChanged("");
|
||||
}
|
||||
|
||||
void YACReaderMacOSXSearchLineEdit::clearText()
|
||||
{
|
||||
// TODO be sure that this will not generate any event....
|
||||
[((NSTextField *)nstextfield) setStringValue:@""];
|
||||
}
|
||||
|
||||
void YACReaderMacOSXSearchLineEdit::setDisabled(bool disabled)
|
||||
{
|
||||
[((NSTextField *)nstextfield) setEnabled:!disabled];
|
||||
}
|
||||
|
||||
void YACReaderMacOSXSearchLineEdit::setEnabled(bool enabled)
|
||||
{
|
||||
[((NSTextField *)nstextfield) setEnabled:enabled];
|
||||
}
|
||||
|
||||
MacToolBarItemWrapper::MacToolBarItemWrapper(QAction *action, QMacToolBarItem *toolbaritem)
|
||||
: action(action), toolbaritem(toolbaritem)
|
||||
{
|
||||
if (action->isCheckable()) {
|
||||
connect(action, &QAction::toggled, this, &MacToolBarItemWrapper::actionToggled);
|
||||
connect(toolbaritem, &QMacToolBarItem::activated, action, &QAction::toggle);
|
||||
updateIcon(action->isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
void MacToolBarItemWrapper::actionToggled(bool toogled)
|
||||
{
|
||||
updateIcon(toogled);
|
||||
}
|
||||
|
||||
void MacToolBarItemWrapper::updateIcon(bool enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
QIcon icon = action->icon();
|
||||
QPixmap tempPixmap = icon.pixmap(QSize(24, 24));
|
||||
QPainter painter;
|
||||
painter.begin(&tempPixmap);
|
||||
painter.fillRect(QRect(3, 21, 18, 1), QColor("#3F3F3F"));
|
||||
painter.fillRect(QRect(3, 22, 18, 1), QColor("#6E6E6E"));
|
||||
painter.fillRect(QRect(3, 23, 18, 1), QColor("#EEEEEE"));
|
||||
painter.end();
|
||||
|
||||
toolbaritem->setIcon(QIcon(tempPixmap));
|
||||
} else
|
||||
toolbaritem->setIcon(action->icon());
|
||||
}
|
||||
#else
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@ -462,9 +67,17 @@ void bindActionToNSToolbarItem(QAction *action, NSToolbarItem *toolbarItem, cons
|
||||
toolbarItem.toolTip = tooltip.isEmpty() ? @"" : [NSString stringWithUTF8String:tooltip.toUtf8().constData()];
|
||||
|
||||
QIcon icon = action->icon();
|
||||
if (icon.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
__auto_type image = QIconToNSImage(icon, { 24, 24 }, iconColor);
|
||||
|
||||
if (image.size.width == 0 || image.size.height == 0) {
|
||||
[image release];
|
||||
return;
|
||||
}
|
||||
|
||||
if (action->isChecked()) {
|
||||
NSSize size = image.size;
|
||||
NSImage *decoratedImage = [[NSImage alloc] initWithSize:size];
|
||||
@ -950,5 +563,3 @@ void YACReaderMacOSXToolbar::hide()
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,81 +1,50 @@
|
||||
#include "yacreader_search_line_edit.h"
|
||||
|
||||
#include "yacreader_global.h"
|
||||
#include "yacreader_global_gui.h"
|
||||
|
||||
#include <QToolButton>
|
||||
#include <QStyle>
|
||||
#include <QLabel>
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
YACReaderSearchLineEdit::YACReaderSearchLineEdit(QWidget *parent)
|
||||
: QLineEdit(parent)
|
||||
: QLineEdit(parent), paddingLeft(0), paddingRight(0)
|
||||
{
|
||||
clearButton = new QToolButton(this);
|
||||
searchLabel = new QLabel(this);
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
QPixmap clearIcon;
|
||||
QPixmap searchIcon;
|
||||
|
||||
clearIcon.setDevicePixelRatio(devicePixelRatioF());
|
||||
searchIcon.setDevicePixelRatio(devicePixelRatioF());
|
||||
|
||||
if (devicePixelRatioF() > 1) {
|
||||
if (!clearIcon.load(":/images/clearSearch@2x.png")) {
|
||||
clearIcon.load(":/images/clearSearch.png");
|
||||
}
|
||||
if (!searchIcon.load(":/images/iconSearch@2x.png")) {
|
||||
searchIcon.load(":/images/iconSearch.png");
|
||||
}
|
||||
} else {
|
||||
clearIcon.load(":/images/clearSearch.png");
|
||||
searchIcon.load(":/images/iconSearch.png");
|
||||
}
|
||||
#else
|
||||
QPixmap clearIcon = YACReader::hdpiPixmap(":/images/clearSearch.svg", QSize(15, 15));
|
||||
QPixmap searchIcon = YACReader::hdpiPixmap(":/images/iconSearch.svg", QSize(15, 15));
|
||||
#endif
|
||||
|
||||
searchLabel->setStyleSheet("QLabel { border: none; padding: 0px; }");
|
||||
searchLabel->setPixmap(searchIcon);
|
||||
|
||||
clearButton->setIcon(QIcon(clearIcon));
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
clearButton->setIconSize(QSize(14, 14));
|
||||
#else
|
||||
clearButton->setIconSize(QSize(12, 12));
|
||||
#endif
|
||||
|
||||
clearButton->setCursor(Qt::ArrowCursor);
|
||||
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||
clearButton->hide();
|
||||
connect(clearButton, &QAbstractButton::clicked, this, &QLineEdit::clear);
|
||||
connect(this, &QLineEdit::textChanged, this, &YACReaderSearchLineEdit::updateCloseButton);
|
||||
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||
#ifdef Y_MAC_UI
|
||||
setStyleSheet(QString("QLineEdit {border-top:1px solid #9F9F9F; border-bottom:1px solid #ACACAC; border-right:1px solid #ACACAC; border-left:1px solid #ACACAC; border-radius: 4px; background-color:#EEEEEE; padding-left: %1px; padding-right: %2px; padding-bottom: 1px; margin-bottom: 1px;} ").arg(searchLabel->sizeHint().width() + frameWidth + 6).arg(clearButton->sizeHint().width() + frameWidth + 2));
|
||||
#else
|
||||
setStyleSheet(QString("QLineEdit {color: #ABABAB; border:none; border-radius: 4px; background-color:#404040; padding-left: %1px; padding-right: %2px; padding-bottom: 1px; margin-right: 9px;} ").arg(searchLabel->sizeHint().width() + frameWidth + 6 + 5).arg(clearButton->sizeHint().width() + frameWidth + 2));
|
||||
#endif
|
||||
paddingLeft = 15 + frameWidth + 6 + 5;
|
||||
paddingRight = 12 + frameWidth + 10;
|
||||
|
||||
QSize msz = minimumSizeHint();
|
||||
setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2),
|
||||
qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2));
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
setMaximumWidth(212);
|
||||
setFixedHeight(26);
|
||||
#else
|
||||
setMaximumWidth(255);
|
||||
setFixedHeight(26);
|
||||
#endif
|
||||
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
setPlaceholderText(tr("type to search"));
|
||||
|
||||
connect(this, &QLineEdit::textChanged, this, &YACReaderSearchLineEdit::processText);
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void YACReaderSearchLineEdit::applyTheme(const Theme &theme)
|
||||
{
|
||||
const auto &searchTheme = theme.searchLineEdit;
|
||||
|
||||
setStyleSheet(searchTheme.lineEditQSS.arg(paddingLeft).arg(paddingRight));
|
||||
searchLabel->setStyleSheet(searchTheme.searchLabelQSS);
|
||||
clearButton->setStyleSheet(searchTheme.clearButtonQSS);
|
||||
|
||||
searchLabel->setPixmap(searchTheme.searchIcon);
|
||||
clearButton->setIcon(QIcon(searchTheme.clearIcon));
|
||||
}
|
||||
|
||||
void YACReaderSearchLineEdit::clearText()
|
||||
@ -92,15 +61,6 @@ const QString YACReaderSearchLineEdit::text()
|
||||
|
||||
void YACReaderSearchLineEdit::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
#ifdef Y_MAC_UI
|
||||
QSize sz = clearButton->sizeHint();
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||
clearButton->move(rect().right() - frameWidth - sz.width(),
|
||||
(rect().bottom() + 1 - sz.height()) / 2);
|
||||
|
||||
QSize szl = searchLabel->sizeHint();
|
||||
searchLabel->move(6, (rect().bottom() + 1 - szl.height()) / 2);
|
||||
#else
|
||||
QSize sz = clearButton->sizeHint();
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||
int marginRight = style()->pixelMetric(QStyle::PM_LayoutRightMargin);
|
||||
@ -109,7 +69,6 @@ void YACReaderSearchLineEdit::resizeEvent(QResizeEvent *)
|
||||
|
||||
QSize szl = searchLabel->sizeHint();
|
||||
searchLabel->move(8, (rect().bottom() + 2 - szl.height()) / 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void YACReaderSearchLineEdit::updateCloseButton(const QString &text)
|
||||
|
||||
@ -5,11 +5,12 @@
|
||||
#include <QCompleter>
|
||||
|
||||
#include "yacreader_global.h"
|
||||
#include "themable.h"
|
||||
|
||||
class QToolButton;
|
||||
class QLabel;
|
||||
|
||||
class YACReaderSearchLineEdit : public QLineEdit
|
||||
class YACReaderSearchLineEdit : public QLineEdit, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -20,6 +21,7 @@ public:
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void applyTheme(const Theme &theme) override;
|
||||
|
||||
signals:
|
||||
void filterChanged(QString);
|
||||
@ -31,6 +33,9 @@ private slots:
|
||||
private:
|
||||
QToolButton *clearButton;
|
||||
QLabel *searchLabel;
|
||||
|
||||
int paddingLeft;
|
||||
int paddingRight;
|
||||
};
|
||||
|
||||
#endif // YACREADER_SEARCH_LINE_EDIT_H
|
||||
|
||||
@ -25,28 +25,14 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent)
|
||||
readingListsView = new YACReaderReadingListsView;
|
||||
selectedLibrary = new YACReaderLibraryListWidget;
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
librariesTitle = new YACReaderTitledToolBar(tr("Libraries"));
|
||||
foldersTitle = new YACReaderTitledToolBar(tr("Folders"));
|
||||
readingListsTitle = new YACReaderTitledToolBar(tr("Reading Lists"));
|
||||
#else
|
||||
librariesTitle = new YACReaderTitledToolBar(tr("LIBRARIES"));
|
||||
foldersTitle = new YACReaderTitledToolBar(tr("FOLDERS"));
|
||||
readingListsTitle = new YACReaderTitledToolBar(tr("READING LISTS"));
|
||||
#endif
|
||||
// Titles will be set from theme in applyTheme
|
||||
librariesTitle = new YACReaderTitledToolBar("");
|
||||
foldersTitle = new YACReaderTitledToolBar("");
|
||||
readingListsTitle = new YACReaderTitledToolBar("");
|
||||
|
||||
splitter = new QSplitter(this);
|
||||
splitter->setOrientation(Qt::Vertical);
|
||||
|
||||
#ifndef Y_MAC_UI
|
||||
splitter->setStyleSheet("QSplitter::handle { "
|
||||
" image: none; background-color = black; "
|
||||
" }"
|
||||
"QSplitter::handle:vertical { height: 39px;}");
|
||||
#else
|
||||
splitter->setStyleSheet("QSplitter::handle:vertical { height: 26px; background-color: transparent;}");
|
||||
#endif
|
||||
|
||||
selectedLibrary->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
selectedLibrary->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
selectedLibrary->setFocusPolicy(Qt::NoFocus);
|
||||
@ -57,24 +43,18 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent)
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// LIBRARIES-------------------------------------------------------
|
||||
#ifndef Y_MAC_UI
|
||||
l->addSpacing(5);
|
||||
#endif
|
||||
|
||||
l->addWidget(librariesTitle);
|
||||
|
||||
#ifndef Y_MAC_UI
|
||||
l->addSpacing(4);
|
||||
l->addWidget(new YACReaderSideBarSeparator(this));
|
||||
auto sep1 = new YACReaderSideBarSeparator(this);
|
||||
separators.append(sep1);
|
||||
l->addWidget(sep1);
|
||||
l->addSpacing(3);
|
||||
#endif
|
||||
|
||||
l->addWidget(selectedLibrary);
|
||||
#ifndef Y_MAC_UI
|
||||
l->addSpacing(11);
|
||||
#else
|
||||
l->addSpacing(6);
|
||||
#endif
|
||||
|
||||
// END LIBRARIES---------------------------------------------------
|
||||
|
||||
@ -84,23 +64,18 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent)
|
||||
foldersLayout->setContentsMargins(0, 0, 0, 0);
|
||||
foldersLayout->setSpacing(0);
|
||||
|
||||
#ifndef Y_MAC_UI
|
||||
// foldersLayout->addSpacing(6);
|
||||
|
||||
// foldersLayout->addSpacing(5);
|
||||
foldersLayout->addWidget(new YACReaderSideBarSeparator(this));
|
||||
auto sep2 = new YACReaderSideBarSeparator(this);
|
||||
separators.append(sep2);
|
||||
foldersLayout->addWidget(sep2);
|
||||
foldersLayout->addSpacing(4);
|
||||
#else
|
||||
// foldersLayout->addSpacing(6);
|
||||
#endif
|
||||
|
||||
foldersLayout->addWidget(foldersTitle);
|
||||
|
||||
#ifndef Y_MAC_UI
|
||||
foldersLayout->addSpacing(4);
|
||||
foldersLayout->addWidget(new YACReaderSideBarSeparator(this));
|
||||
auto sep3 = new YACReaderSideBarSeparator(this);
|
||||
separators.append(sep3);
|
||||
foldersLayout->addWidget(sep3);
|
||||
foldersLayout->addSpacing(4);
|
||||
#endif
|
||||
|
||||
foldersLayout->addWidget(foldersView);
|
||||
foldersLayout->addSpacing(6);
|
||||
@ -116,28 +91,21 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent)
|
||||
readingListsHeaderLayout->setContentsMargins(0, 0, 0, 0);
|
||||
readingListsHeaderLayout->setSpacing(0);
|
||||
|
||||
#ifndef Y_MAC_UI
|
||||
// readingListsHeaderLayout->addSpacing(6);
|
||||
|
||||
// readingListsHeaderLayout->addSpacing(5);
|
||||
readingListsHeaderLayout->addWidget(new YACReaderSideBarSeparator(this));
|
||||
auto sep4 = new YACReaderSideBarSeparator(this);
|
||||
separators.append(sep4);
|
||||
readingListsHeaderLayout->addWidget(sep4);
|
||||
readingListsHeaderLayout->addSpacing(4);
|
||||
#else
|
||||
// readingListsHeaderLayout->addSpacing(6);
|
||||
#endif
|
||||
|
||||
readingListsHeaderLayout->addWidget(readingListsTitle);
|
||||
|
||||
#ifndef Y_MAC_UI
|
||||
readingListsHeaderLayout->addSpacing(4);
|
||||
readingListsHeaderLayout->addWidget(new YACReaderSideBarSeparator(this));
|
||||
auto sep5 = new YACReaderSideBarSeparator(this);
|
||||
separators.append(sep5);
|
||||
readingListsHeaderLayout->addWidget(sep5);
|
||||
readingListsHeaderLayout->addSpacing(4);
|
||||
#endif
|
||||
|
||||
// readingListsLayout->addWidget(readingListsView);
|
||||
readingListsHeaderLayout->addStretch();
|
||||
QSplitterHandle *handle = splitter->handle(1);
|
||||
// handle->setCursor(QCursor(Qt::ArrowCursor));
|
||||
handle->setLayout(readingListsHeaderLayout);
|
||||
// END READING LISTS------------------------------------------------
|
||||
|
||||
@ -148,30 +116,16 @@ YACReaderSideBar::YACReaderSideBar(QWidget *parent)
|
||||
|
||||
if (settings->contains(SIDEBAR_SPLITTER_STATUS))
|
||||
splitter->restoreState(settings->value(SIDEBAR_SPLITTER_STATUS).toByteArray());
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void YACReaderSideBar::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(0, 0, width(), height(), QColor("#F1F1F1"));
|
||||
#else
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(0, 0, width(), height(), QColor("#454545"));
|
||||
// QWidget::paintEvent(event);
|
||||
#endif
|
||||
|
||||
// QPixmap shadow(":/images/side_bar/shadow.png");
|
||||
// painter.drawPixmap(width()-shadow.width(),0,shadow.width(),height(),shadow);
|
||||
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
// painter.drawLine(rect().topLeft(), rect().bottomRight());
|
||||
|
||||
// QWidget::paintEvent(event);
|
||||
painter.fillRect(0, 0, width(), height(), theme.sidebar.backgroundColor);
|
||||
}
|
||||
|
||||
void YACReaderSideBar::closeEvent(QCloseEvent *event)
|
||||
@ -186,17 +140,40 @@ QSize YACReaderSideBar::sizeHint() const
|
||||
return QSize(275, 200);
|
||||
}
|
||||
|
||||
void YACReaderSideBar::applyTheme(const Theme &theme)
|
||||
{
|
||||
splitter->setStyleSheet(theme.sidebar.splitterQSS);
|
||||
|
||||
// Titles are per-instance, toolbars handle their own colors via Themable
|
||||
auto applyCase = [&](const QString &s) { return theme.sidebar.uppercaseLabels ? s.toUpper() : s; };
|
||||
librariesTitle->setTitle(applyCase(QObject::tr("Libraries")));
|
||||
foldersTitle->setTitle(applyCase(QObject::tr("Folders")));
|
||||
readingListsTitle->setTitle(applyCase(QObject::tr("Reading Lists")));
|
||||
|
||||
for (auto separator : separators) {
|
||||
separator->setColor(theme.sidebar.sectionSeparatorColor);
|
||||
}
|
||||
|
||||
update(); // Trigger repaint for background color
|
||||
}
|
||||
|
||||
YACReaderSideBarSeparator::YACReaderSideBarSeparator(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent), separatorColor(QColor("#575757"))
|
||||
{
|
||||
setFixedHeight(1);
|
||||
}
|
||||
|
||||
void YACReaderSideBarSeparator::setColor(const QColor &color)
|
||||
{
|
||||
separatorColor = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void YACReaderSideBarSeparator::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(5, 0, width() - 10, height(), QColor("#575757"));
|
||||
painter.fillRect(5, 0, width() - 10, height(), separatorColor);
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "themable.h"
|
||||
|
||||
class YACReaderFoldersView;
|
||||
class YACReaderLibraryListWidget;
|
||||
class YACReaderSearchLineEdit;
|
||||
@ -14,12 +16,16 @@ class YACReaderSideBarSeparator : public QWidget
|
||||
{
|
||||
public:
|
||||
explicit YACReaderSideBarSeparator(QWidget *parent = 0);
|
||||
void setColor(const QColor &color);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
QColor separatorColor;
|
||||
};
|
||||
|
||||
class YACReaderSideBar : public QWidget
|
||||
class YACReaderSideBar : public QWidget, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -40,8 +46,11 @@ public slots:
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void applyTheme(const Theme &theme) override;
|
||||
|
||||
QSettings *settings;
|
||||
QSplitter *splitter;
|
||||
QList<YACReaderSideBarSeparator *> separators;
|
||||
};
|
||||
|
||||
#endif // YACREADER_SIDEBAR_H
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QResizeEvent>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPainter>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
@ -19,26 +18,11 @@
|
||||
#include "comic_model.h"
|
||||
|
||||
YACReaderTableView::YACReaderTableView(QWidget *parent)
|
||||
: QTableView(parent), showDelete(false), editing(false), myeditor(0)
|
||||
: QTableView(parent), editing(false), myeditor(0)
|
||||
{
|
||||
setAlternatingRowColors(true);
|
||||
verticalHeader()->setAlternatingRowColors(true);
|
||||
setStyleSheet("QTableView {alternate-background-color: #F2F2F2;background-color: #FAFAFA; outline: 0px;}" // border: 1px solid #999999; border-right:none; border-bottom:none;}"
|
||||
"QTableCornerButton::section {background-color:#F5F5F5; border:none; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4);}"
|
||||
"QTableView::item {outline: 0px; border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE; padding-bottom:1px; color:#252626;}"
|
||||
"QTableView {border-top:1px solid #B8B8B8;border-bottom:none;border-left:1px solid #B8B8B8;border-right:none;}"
|
||||
#ifdef Y_MAC_UI
|
||||
"QTableView {border-top:1px solid #B8B8B8;border-bottom:none;border-left:none;border-right:none;}"
|
||||
"QTableView::item:selected {outline: 0px; border-bottom: 1px solid #3875D7;border-top: 1px solid #3875D7; padding-bottom:1px; background-color: #3875D7; color: #FFFFFF; }"
|
||||
|
||||
#else
|
||||
"QTableView::item:selected {outline: 0px; border-bottom: 1px solid #D4D4D4;border-top: 1px solid #D4D4D4; padding-bottom:1px; background-color: #D4D4D4; }"
|
||||
#endif
|
||||
"QHeaderView::section:horizontal {background-color:#F5F5F5; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4); border-left:none; border-top:none; padding:4px; color:#313232;}"
|
||||
"QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}"
|
||||
//"QTableView::item:hover {border-bottom: 1px solid #A3A3A3;border-top: 1px solid #A3A3A3; padding-bottom:1px; background-color: #A3A3A3; color: #FFFFFF; }"
|
||||
"");
|
||||
// comicView->setItemDelegate(new YACReaderComicViewDelegate());
|
||||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
setShowGrid(false);
|
||||
@ -72,16 +56,19 @@ YACReaderTableView::YACReaderTableView(QWidget *parent)
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
|
||||
setMouseTracking(true);
|
||||
/*deletingProgress = new YACReaderDeletingProgress(this);
|
||||
|
||||
showDeletingProgressAnimation = new QPropertyAnimation(deletingProgress,"pos");
|
||||
showDeletingProgressAnimation->setDuration(150);*/
|
||||
|
||||
// drag: if the default drag is enabled there is no way for setting a custom image
|
||||
// TODO report bug/suggestion
|
||||
// setDragEnabled(true);
|
||||
// setDragDropMode(QAbstractItemView::DragDrop);
|
||||
setAcceptDrops(true);
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void YACReaderTableView::applyTheme(const Theme &theme)
|
||||
{
|
||||
setStyleSheet(theme.tableView.tableViewQSS);
|
||||
}
|
||||
|
||||
void YACReaderTableView::mouseMoveEvent(QMouseEvent *event)
|
||||
@ -204,36 +191,8 @@ void YACReaderTableView::commitData(QWidget *editor)
|
||||
emit comicRated(((StarEditor *)editor)->starRating().starCount(), currentIndexEditing);
|
||||
}
|
||||
|
||||
void YACReaderTableView::showDeleteProgress()
|
||||
{
|
||||
/*showDelete = true;
|
||||
|
||||
showDeletingProgressAnimation->setStartValue(deletingProgress->pos());
|
||||
showDeletingProgressAnimation->setEndValue(QPoint((width()-deletingProgress->width())/2 ,1));
|
||||
showDeletingProgressAnimation->start();*/
|
||||
}
|
||||
|
||||
void YACReaderTableView::hideDeleteProgress()
|
||||
{
|
||||
/*showDelete = false;
|
||||
|
||||
if(showDeletingProgressAnimation->state()==QPropertyAnimation::Running)
|
||||
showDeletingProgressAnimation->stop();
|
||||
|
||||
showDeletingProgressAnimation->setStartValue(deletingProgress->pos());
|
||||
showDeletingProgressAnimation->setEndValue(QPoint((width()-deletingProgress->width())/2 ,-deletingProgress->height()));
|
||||
showDeletingProgressAnimation->start();*/
|
||||
}
|
||||
|
||||
void YACReaderTableView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
/*event->size();
|
||||
|
||||
if(showDelete)
|
||||
deletingProgress->move((event->size().width()-deletingProgress->width())/2 ,1);
|
||||
else
|
||||
deletingProgress->move((event->size().width()-deletingProgress->width())/2 ,-deletingProgress->height());*/
|
||||
|
||||
QTableView::resizeEvent(event);
|
||||
}
|
||||
|
||||
@ -247,15 +206,23 @@ void YACReaderRatingDelegate::paint(QPainter *painter, const QStyleOptionViewIte
|
||||
|
||||
StarRating starRating(rating);
|
||||
|
||||
// Get colors from parent table view
|
||||
QColor ratingColor(0xE9BE0F);
|
||||
QColor ratingSelectedColor(Qt::white);
|
||||
if (auto tableView = qobject_cast<YACReaderTableView *>(parent())) {
|
||||
ratingColor = tableView->starRatingColor();
|
||||
ratingSelectedColor = tableView->starRatingSelectedColor();
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (!(option.state & QStyle::State_Editing)) {
|
||||
if (option.state & QStyle::State_Selected)
|
||||
starRating.paintSelected(painter, option.rect, option.palette,
|
||||
StarRating::ReadOnly);
|
||||
StarRating::ReadOnly, ratingSelectedColor);
|
||||
else
|
||||
starRating.paint(painter, option.rect, option.palette,
|
||||
StarRating::ReadOnly);
|
||||
StarRating::ReadOnly, ratingColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,6 +311,12 @@ QSize StarRating::sizeHint() const
|
||||
|
||||
void StarRating::paint(QPainter *painter, const QRect &rect,
|
||||
const QPalette &palette, EditMode mode) const
|
||||
{
|
||||
paint(painter, rect, palette, mode, QColor("#e9be0f"));
|
||||
}
|
||||
|
||||
void StarRating::paint(QPainter *painter, const QRect &rect,
|
||||
const QPalette &palette, EditMode mode, QColor color) const
|
||||
{
|
||||
Q_UNUSED(palette)
|
||||
painter->save();
|
||||
@ -351,12 +324,8 @@ void StarRating::paint(QPainter *painter, const QRect &rect,
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setPen(Qt::NoPen);
|
||||
|
||||
// if (mode == Editable) {
|
||||
// painter->setBrush(palette.highlight());
|
||||
// } else {
|
||||
QBrush brush(QColor("#e9be0f"));
|
||||
QBrush brush(color);
|
||||
painter->setBrush(brush);
|
||||
//}
|
||||
|
||||
int yOffset = (rect.height() - PaintingScaleFactor) / 2;
|
||||
painter->translate(rect.x(), rect.y() + yOffset);
|
||||
@ -366,7 +335,7 @@ void StarRating::paint(QPainter *painter, const QRect &rect,
|
||||
if (i < myStarCount) {
|
||||
painter->drawPolygon(starPolygon, Qt::WindingFill);
|
||||
} else if (mode == Editable) {
|
||||
painter->drawEllipse(QPointF(0.5, 0.5), 0.08, 0.08); //(diamondPolygon, Qt::WindingFill);
|
||||
painter->drawEllipse(QPointF(0.5, 0.5), 0.08, 0.08);
|
||||
}
|
||||
painter->translate(1.0, 0.0);
|
||||
}
|
||||
|
||||
@ -4,21 +4,24 @@
|
||||
#include <QTableView>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class YACReaderDeletingProgress;
|
||||
class QResizeEvent;
|
||||
class QPropertyAnimation;
|
||||
#include "themable.h"
|
||||
|
||||
class YACReaderTableView : public QTableView
|
||||
class QResizeEvent;
|
||||
|
||||
class YACReaderTableView : public QTableView, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit YACReaderTableView(QWidget *parent = 0);
|
||||
QColor starRatingColor() const { return theme.tableView.starRatingColor; }
|
||||
QColor starRatingSelectedColor() const { return theme.tableView.starRatingSelectedColor; }
|
||||
|
||||
protected:
|
||||
void applyTheme(const Theme &theme) override;
|
||||
|
||||
signals:
|
||||
void comicRated(int, QModelIndex);
|
||||
public slots:
|
||||
void showDeleteProgress();
|
||||
void hideDeleteProgress();
|
||||
void closeRatingEditor();
|
||||
protected slots:
|
||||
|
||||
@ -26,10 +29,6 @@ protected slots:
|
||||
virtual void commitData(QWidget *editor);
|
||||
|
||||
private:
|
||||
YACReaderDeletingProgress *deletingProgress;
|
||||
bool showDelete;
|
||||
QPropertyAnimation *showDeletingProgressAnimation;
|
||||
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
@ -84,6 +83,8 @@ public:
|
||||
|
||||
void paint(QPainter *painter, const QRect &rect,
|
||||
const QPalette &palette, EditMode mode) const;
|
||||
void paint(QPainter *painter, const QRect &rect,
|
||||
const QPalette &palette, EditMode mode, QColor color) const;
|
||||
void paintSelected(QPainter *painter, const QRect &rect,
|
||||
const QPalette &palette, EditMode mode, QColor color) const;
|
||||
void paintSelected(QPainter *painter, const QRect &rect,
|
||||
|
||||
@ -43,9 +43,7 @@ void DropShadowLabel::paintEvent(QPaintEvent *event)
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setFont(font());
|
||||
#ifndef Y_MAC_UI
|
||||
drawTextEffect(&painter, QPoint(contentsMargins().left(), 1));
|
||||
#endif
|
||||
drawText(&painter, QPoint(contentsMargins().left(), 0));
|
||||
}
|
||||
|
||||
@ -73,23 +71,10 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString &title, QWidget *pa
|
||||
busyIndicator = new BusyIndicator(this, 12);
|
||||
connect(busyIndicator, &BusyIndicator::clicked, this, &YACReaderTitledToolBar::cancelOperationRequested);
|
||||
busyIndicator->setIndicatorStyle(BusyIndicator::StyleArc);
|
||||
#ifdef Y_MAC_UI
|
||||
busyIndicator->setColor(QColor("#808080"));
|
||||
#else
|
||||
busyIndicator->setColor(Qt::white);
|
||||
#endif
|
||||
busyIndicator->setHidden(true);
|
||||
|
||||
nameLabel->setText(title);
|
||||
#ifdef Y_MAC_UI
|
||||
QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}";
|
||||
nameLabel->setColor(QColor("#808080"));
|
||||
// nameLabel->setDropShadowColor(QColor("#F9FAFB"));
|
||||
#else
|
||||
QString nameLabelStyleSheet = "QLabel {padding:0 0 0 10px; margin:0px; font-size:11px; font-weight:bold;}";
|
||||
nameLabel->setColor(QColor("#BDBFBF"));
|
||||
nameLabel->setDropShadowColor(QColor("#000000"));
|
||||
#endif
|
||||
nameLabel->setStyleSheet(nameLabelStyleSheet);
|
||||
|
||||
mainLayout->addWidget(nameLabel);
|
||||
@ -101,32 +86,21 @@ YACReaderTitledToolBar::YACReaderTitledToolBar(const QString &title, QWidget *pa
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
setMinimumHeight(25);
|
||||
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void YACReaderTitledToolBar::addAction(QAction *action)
|
||||
{
|
||||
QHBoxLayout *mainLayout = dynamic_cast<QHBoxLayout *>(layout());
|
||||
|
||||
// fix for QToolButton and retina support in OSX
|
||||
#ifdef Q_OS_MACOS // TODO_Y_MAC_UI
|
||||
QPushButton *pb = new QPushButton(this);
|
||||
pb->setCursor(QCursor(Qt::ArrowCursor));
|
||||
pb->setIcon(action->icon());
|
||||
pb->addAction(action);
|
||||
|
||||
connect(pb, &QPushButton::clicked, action, &QAction::triggered);
|
||||
|
||||
mainLayout->addWidget(pb);
|
||||
#else
|
||||
QToolButton *tb = new QToolButton(this);
|
||||
tb->setCursor(QCursor(Qt::ArrowCursor));
|
||||
tb->setDefaultAction(action);
|
||||
tb->setIconSize(QSize(16, 16));
|
||||
tb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
// tb->setStyleSheet("QToolButton:hover {background-color:#C5C5C5;}");
|
||||
|
||||
mainLayout->addWidget(tb);
|
||||
#endif
|
||||
}
|
||||
|
||||
void YACReaderTitledToolBar::addSpacing(int spacing)
|
||||
@ -142,11 +116,8 @@ void YACReaderTitledToolBar::addSepartor()
|
||||
|
||||
QWidget *w = new QWidget(this);
|
||||
w->setFixedSize(1, 14);
|
||||
#ifdef Y_MAC_UI
|
||||
w->setStyleSheet("QWidget {background-color:#AFAFAF;}");
|
||||
#else
|
||||
w->setStyleSheet("QWidget {background-color:#6F6F6F;}");
|
||||
#endif
|
||||
w->setStyleSheet(QString("QWidget {background-color:%1;}").arg(theme.sidebar.separatorColor.name()));
|
||||
separators.append(w);
|
||||
|
||||
mainLayout->addSpacing(10);
|
||||
mainLayout->addWidget(w);
|
||||
@ -162,3 +133,24 @@ void YACReaderTitledToolBar::hideBusyIndicator()
|
||||
{
|
||||
busyIndicator->setHidden(true);
|
||||
}
|
||||
|
||||
void YACReaderTitledToolBar::setTitle(const QString &title)
|
||||
{
|
||||
nameLabel->setText(title);
|
||||
}
|
||||
|
||||
void YACReaderTitledToolBar::applyTheme(const Theme &theme)
|
||||
{
|
||||
auto sidebarTheme = theme.sidebar;
|
||||
|
||||
nameLabel->setColor(sidebarTheme.titleTextColor);
|
||||
nameLabel->setDropShadowColor(sidebarTheme.titleDropShadowColor);
|
||||
nameLabel->update();
|
||||
|
||||
busyIndicator->setColor(sidebarTheme.busyIndicatorColor);
|
||||
|
||||
QString qss = QString("QWidget {background-color:%1;}").arg(sidebarTheme.separatorColor.name());
|
||||
for (auto separator : separators) {
|
||||
separator->setStyleSheet(qss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include <QPainter>
|
||||
#include <QPoint>
|
||||
|
||||
#include "themable.h"
|
||||
|
||||
class QIcon;
|
||||
class BusyIndicator;
|
||||
|
||||
@ -27,7 +29,7 @@ private:
|
||||
void drawTextEffect(QPainter *painter, QPoint offset);
|
||||
};
|
||||
|
||||
class YACReaderTitledToolBar : public QWidget
|
||||
class YACReaderTitledToolBar : public QWidget, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -42,10 +44,15 @@ public slots:
|
||||
void addSepartor();
|
||||
void showBusyIndicator();
|
||||
void hideBusyIndicator();
|
||||
void setTitle(const QString &title);
|
||||
|
||||
protected:
|
||||
void applyTheme(const Theme &theme) override;
|
||||
|
||||
private:
|
||||
DropShadowLabel *nameLabel;
|
||||
BusyIndicator *busyIndicator;
|
||||
QList<QWidget *> separators;
|
||||
};
|
||||
|
||||
#endif // YACREADER_TITLED_TOOLBAR_H
|
||||
|
||||
@ -9,10 +9,6 @@ YACReaderTreeView::YACReaderTreeView(QWidget *parent)
|
||||
setDragDropMode(QAbstractItemView::DropOnly);
|
||||
setItemsExpandable(true);
|
||||
|
||||
// setDragEnabled(true);
|
||||
/*viewport()->setAcceptDrops(true);
|
||||
setDropIndicatorShown(true);*/
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
header()->hide();
|
||||
@ -20,38 +16,12 @@ YACReaderTreeView::YACReaderTreeView(QWidget *parent)
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
setStyleSheet("QTreeView {background-color:transparent; border: none;}"
|
||||
"QTreeView::item:selected {background-color:#91c4f4; border-top: 1px solid #91c4f4; border-left:none;border-right:none;border-bottom:1px solid #91c4f4;}"
|
||||
"QTreeView::branch:selected {background-color:#91c4f4; border-top: 1px solid #91c4f4; border-left:none;border-right:none;border-bottom:1px solid #91c4f4;}"
|
||||
"QTreeView::branch:open:selected:has-children {image: url(':/images/sidebar/expanded_branch_osx.png');}"
|
||||
"QTreeView::branch:closed:selected:has-children {image: url(':/images/sidebar/collapsed_branch_osx.png');}"
|
||||
|
||||
);
|
||||
|
||||
#else
|
||||
setStyleSheet("QTreeView {background-color:transparent; border: none; color:#DDDFDF; outline:0; show-decoration-selected: 0;}"
|
||||
"QTreeView::item:selected {background-color: #2E2E2E; color:white; font:bold;}"
|
||||
"QTreeView::item:hover {background-color:#2E2E2E; color:white; font:bold;}"
|
||||
"QTreeView::branch:selected {background-color:#2E2E2E;}"
|
||||
|
||||
"QScrollBar:vertical { border: none; background: #404040; width: 7px; margin: 0 3px 0 0; }"
|
||||
"QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }"
|
||||
"QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}"
|
||||
|
||||
"QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}"
|
||||
"QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}"
|
||||
"QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}"
|
||||
|
||||
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }"
|
||||
|
||||
"QTreeView::branch:has-children:!has-siblings:closed,QTreeView::branch:closed:has-children:has-siblings {border-image: none;image: url(':/images/sidebar/branch-closed.svg');}"
|
||||
"QTreeView::branch:has-children:selected:!has-siblings:closed,QTreeView::branch:closed:selected:has-children:has-siblings {border-image: none;image: url(':/images/sidebar/collapsed_branch_selected.png');}"
|
||||
|
||||
"QTreeView::branch:open:has-children:!has-siblings,QTreeView::branch:open:has-children:has-siblings {border-image: none;image: url(':/images/sidebar/branch-open.svg');}"
|
||||
"QTreeView::branch:open:has-children:selected:!has-siblings,QTreeView::branch:open:has-children:selected:has-siblings {border-image: none;image: url(':/images/sidebar/expanded_branch_selected.png');}");
|
||||
#endif
|
||||
void YACReaderTreeView::applyTheme(const Theme &theme)
|
||||
{
|
||||
setStyleSheet(theme.treeView.treeViewQSS);
|
||||
}
|
||||
|
||||
void YACReaderTreeView::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
@ -3,11 +3,16 @@
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
class YACReaderTreeView : public QTreeView
|
||||
#include "themable.h"
|
||||
|
||||
class YACReaderTreeView : public QTreeView, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit YACReaderTreeView(QWidget *parent = 0);
|
||||
QColor folderIndicatorColor() const { return theme.treeView.folderIndicatorColor; }
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
signals:
|
||||
@ -24,6 +29,7 @@ protected:
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
||||
void applyTheme(const Theme &theme) override;
|
||||
|
||||
// fix for drop auto expand
|
||||
QTimer expandTimer;
|
||||
|
||||
Reference in New Issue
Block a user