mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Make code compatible with QT 5.9 (#1553)
* Make code compatible with QT 5.9, Ubuntu 18.04. * Fix high dpi scaling in ColorThemeListView.
This commit is contained in:
parent
051eb3aaf3
commit
1aabddc3f6
@ -1,7 +1,9 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
include(DisallowInSource)
|
||||
|
@ -61,8 +61,8 @@ int main(int argc, char *argv[])
|
||||
continue;
|
||||
}
|
||||
QJsonObject updatedTheme;
|
||||
auto sch = ThemeWorker().getTheme(theme);
|
||||
for (auto key : sch.object().keys()) {
|
||||
auto sch = ThemeWorker().getTheme(theme).object();
|
||||
for (auto key : sch.keys()) {
|
||||
if (options.contains(key)) {
|
||||
updatedTheme.insert(key, sch[key]);
|
||||
}
|
||||
|
@ -22,7 +22,10 @@ ColorThemeEditDialog::ColorThemeEditDialog(QWidget *parent) :
|
||||
previewDisasmWidget = new DisassemblyWidget(nullptr);
|
||||
previewDisasmWidget->setObjectName("Preview Disasm");
|
||||
previewDisasmWidget->setPreviewMode(true);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
// default size limit is acceptable
|
||||
previewDisasmWidget->setMinimumSize(qApp->screenAt(previewDisasmWidget->pos())->size() * 0.5);
|
||||
#endif
|
||||
previewDisasmWidget->setWindowTitle(tr("Disassembly Preview"));
|
||||
previewDisasmWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
ui->colorPickerAndPreviewLayout->addWidget(previewDisasmWidget);
|
||||
|
@ -194,8 +194,7 @@ ColorPicker::ColorPicker(QWidget* parent) :
|
||||
ColorPicker::~ColorPicker()
|
||||
{
|
||||
if (pickingFromScreen) {
|
||||
setColor(QApplication::screenAt(QCursor::pos())->grabWindow(QApplication::desktop()->winId())
|
||||
.toImage().pixelColor(QCursor::pos()));
|
||||
setColor(getColorAtMouse());
|
||||
stopPickingFromScreen();
|
||||
}
|
||||
}
|
||||
@ -282,11 +281,7 @@ void ColorPicker::startPickingFromScreen()
|
||||
void ColorPicker::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (pickingFromScreen) {
|
||||
const QDesktopWidget *desktop = QApplication::desktop();
|
||||
const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())
|
||||
->grabWindow(desktop->winId(),
|
||||
QCursor::pos().x(), QCursor::pos().y(), 1, 1);
|
||||
setColor(pixmap.toImage().pixel(0, 0));
|
||||
setColor(getColorAtMouse());
|
||||
pickingFromScreen = false;
|
||||
setMouseTracking(false);
|
||||
releaseMouse();
|
||||
@ -297,13 +292,18 @@ void ColorPicker::mouseReleaseEvent(QMouseEvent* event)
|
||||
void ColorPicker::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (pickingFromScreen) {
|
||||
updateColor(getColorAtMouse());
|
||||
}
|
||||
QWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
QColor ColorPicker::getColorAtMouse()
|
||||
{
|
||||
const QDesktopWidget *desktop = QApplication::desktop();
|
||||
const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())
|
||||
->grabWindow(desktop->winId(),
|
||||
QCursor::pos().x(), QCursor::pos().y(), 1, 1);
|
||||
updateColor(pixmap.toImage().pixel(0, 0));
|
||||
}
|
||||
QWidget::mouseMoveEvent(event);
|
||||
return pixmap.toImage().pixelColor(0, 0);
|
||||
}
|
||||
|
||||
bool ColorPicker::isPickingFromScreen() const
|
||||
|
@ -79,6 +79,8 @@ private:
|
||||
Ui::ColorPicker *ui;
|
||||
bool pickingFromScreen;
|
||||
|
||||
QColor getColorAtMouse();
|
||||
|
||||
/**
|
||||
* @brief bufferColor is used to buffer current color while picking from screen.
|
||||
*/
|
||||
|
@ -37,7 +37,7 @@ void ColorOptionDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
int margin = this->margin * qApp->screenAt(option.rect.topLeft())->devicePixelRatio();
|
||||
int margin = this->margin * painter->device()->devicePixelRatioF();
|
||||
painter->save();
|
||||
painter->setFont(option.font);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
@ -88,10 +88,16 @@ void ColorOptionDelegate::paint(QPainter *painter,
|
||||
resetButtonRect.setSize(resetButtonRect.size() * 1.0);
|
||||
}
|
||||
} else {
|
||||
QColor c = qApp->palette().placeholderText().color();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
QColor placeholderColor = qApp->palette().placeholderText().color();
|
||||
#else
|
||||
QColor placeholderColor = qApp->palette().text().color();
|
||||
placeholderColor.setAlphaF(0.5);
|
||||
#endif
|
||||
QColor c = placeholderColor;
|
||||
c.setAlphaF(0.2);
|
||||
br = c;
|
||||
pen = QPen(qApp->palette().placeholderText().color().darker(), margin / 2);
|
||||
pen = QPen(placeholderColor.darker(), margin / 2);
|
||||
}
|
||||
|
||||
painter->fillRect(option.rect, br);
|
||||
@ -143,9 +149,9 @@ void ColorOptionDelegate::paint(QPainter *painter,
|
||||
|
||||
QSize ColorOptionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
int margin = this->margin * qApp->screenAt(option.rect.topLeft())->devicePixelRatio();
|
||||
int fontHeight = option.fontMetrics.height();
|
||||
int h = QPen().width();
|
||||
qreal margin = this->margin * option.widget->devicePixelRatioF();
|
||||
qreal fontHeight = option.fontMetrics.height();
|
||||
qreal h = QPen().width();
|
||||
h += fontHeight; // option name
|
||||
h += margin / 2; // margin between option rect and option name
|
||||
h += margin / 4; // margin betveen option rect and color rect
|
||||
@ -154,7 +160,7 @@ QSize ColorOptionDelegate::sizeHint(const QStyleOptionViewItem& option, const QM
|
||||
h += margin; // last margin
|
||||
|
||||
Q_UNUSED(index)
|
||||
return QSize(-1, h);
|
||||
return QSize(-1, qRound(h));
|
||||
}
|
||||
|
||||
QRect ColorOptionDelegate::getResetButtonRect() const
|
||||
@ -187,6 +193,7 @@ ColorThemeListView::ColorThemeListView(QWidget *parent) :
|
||||
setModel(new ColorSettingsModel(static_cast<QObject *>(this)));
|
||||
static_cast<ColorSettingsModel *>(this->model())->updateTheme();
|
||||
setItemDelegate(new ColorOptionDelegate(this));
|
||||
setResizeMode(ResizeMode::Adjust);
|
||||
|
||||
QJsonArray rgb = qobject_cast<ColorSettingsModel*>(model())->getTheme()
|
||||
.object().find("gui.background").value().toArray();
|
||||
@ -235,7 +242,8 @@ void ColorThemeListView::mouseReleaseEvent(QMouseEvent* e)
|
||||
auto model = qobject_cast<ColorSettingsModel*>(this->model());
|
||||
ColorOption co = currentIndex().data(Qt::UserRole).value<ColorOption>();
|
||||
co.changed = false;
|
||||
QJsonArray rgb = ThemeWorker().getTheme(Config()->getColorTheme())[co.optionName].toArray();
|
||||
QJsonArray rgb = ThemeWorker().getTheme(
|
||||
Config()->getColorTheme()).object()[co.optionName].toArray();
|
||||
co.color = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
||||
model->setData(currentIndex(), QVariant::fromValue(co));
|
||||
QCursor c;
|
||||
|
Loading…
Reference in New Issue
Block a user