mirror of git://sigrok.org/pulseview
pv: adjust application source code for Qt6 support
Prepare application source code (C++ programming language files) for Qt6 compatibility. Implement alternative code paths where the API has changed compared to Qt5. This unbreaks Mac OSX 12 builds with homebrew. This change is based on work that was submitted by Dominik Sliwa <dominik@sliwa.io>.
This commit is contained in:
parent
fa8d0fcb4c
commit
1ed73ebd60
|
@ -106,7 +106,11 @@ void Application::switch_language(const QString& language)
|
|||
qWarning() << "Translation resource" << resource << "not found";
|
||||
|
||||
// Qt translations
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QString tr_path(QLibraryInfo::path(QLibraryInfo::TranslationsPath));
|
||||
#else
|
||||
QString tr_path(QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
#endif
|
||||
|
||||
if (qt_translator_.load("qt_" + language, tr_path))
|
||||
installTranslator(&qt_translator_);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include <limits>
|
||||
|
||||
#include <QDebug>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QRegularExpression>
|
||||
#endif
|
||||
|
||||
#include "logic.hpp"
|
||||
#include "logicsegment.hpp"
|
||||
|
@ -306,7 +309,11 @@ void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
|
|||
continue;
|
||||
|
||||
QString ch_name = ch.name.toLower();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
ch_name = ch_name.replace(QRegularExpression("[-_.]"), " ");
|
||||
#else
|
||||
ch_name = ch_name.replace(QRegExp("[-_.]"), " ");
|
||||
#endif
|
||||
|
||||
shared_ptr<data::SignalBase> match;
|
||||
for (const shared_ptr<data::SignalBase>& s : session_.signalbases()) {
|
||||
|
@ -314,7 +321,11 @@ void DecodeSignal::auto_assign_signals(const shared_ptr<Decoder> dec)
|
|||
continue;
|
||||
|
||||
QString s_name = s->name().toLower();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
s_name = s_name.replace(QRegularExpression("[-_.]"), " ");
|
||||
#else
|
||||
s_name = s_name.replace(QRegExp("[-_.]"), " ");
|
||||
#endif
|
||||
|
||||
if (s->logic_data() &&
|
||||
((ch_name.contains(s_name)) || (s_name.contains(ch_name)))) {
|
||||
|
@ -747,7 +758,11 @@ void DecodeSignal::save_settings(QSettings &settings) const
|
|||
for (const shared_ptr<Decoder>& decoder : stack_) {
|
||||
settings.beginGroup("decoder" + QString::number(decoder_idx++));
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
settings.setValue("id", (const char *)decoder->get_srd_decoder()->id);
|
||||
#else
|
||||
settings.setValue("id", decoder->get_srd_decoder()->id);
|
||||
#endif
|
||||
settings.setValue("visible", decoder->visible());
|
||||
|
||||
// Save decoder options
|
||||
|
|
|
@ -590,7 +590,12 @@ void SignalBase::restore_settings(QSettings &settings)
|
|||
QVariant value = settings.value("color");
|
||||
|
||||
// Workaround for Qt QColor serialization bug on OSX
|
||||
if ((QMetaType::Type)(value.type()) == QMetaType::QColor)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool is_qcolor = (QMetaType::Type)(value.typeId()) == QMetaType::QColor;
|
||||
#else
|
||||
bool is_qcolor = (QMetaType::Type)(value.type()) == QMetaType::QColor;
|
||||
#endif
|
||||
if (is_qcolor)
|
||||
set_color(value.value<QColor>());
|
||||
else
|
||||
set_color(QColor::fromRgba(value.value<uint32_t>()));
|
||||
|
|
|
@ -231,8 +231,13 @@ QWidget *Settings::get_general_settings_form(QWidget *parent) const
|
|||
language_cb->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(language_cb, SIGNAL(currentTextChanged(const QString&)),
|
||||
this, SLOT(on_general_language_changed(const QString&)));
|
||||
#else
|
||||
connect(language_cb, SIGNAL(currentIndexChanged(const QString&)),
|
||||
this, SLOT(on_general_language_changed(const QString&)));
|
||||
#endif
|
||||
general_layout->addRow(tr("User interface language"), language_cb);
|
||||
|
||||
// Theme combobox
|
||||
|
|
|
@ -330,7 +330,11 @@ void GlobalSettings::store_gvariant(QSettings &settings, GVariant *v)
|
|||
g_variant_get_size(v));
|
||||
|
||||
settings.setValue("value", var_data);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
settings.setValue("type", (const char *)var_type_str);
|
||||
#else
|
||||
settings.setValue("type", var_type_str);
|
||||
#endif
|
||||
|
||||
g_free(var_type_str);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ MainWindow::~MainWindow()
|
|||
void MainWindow::show_session_error(const QString text, const QString info_text)
|
||||
{
|
||||
// TODO Emulate noquote()
|
||||
qDebug() << "Notifying user of session error:" << info_text;
|
||||
qDebug() << "Notifying user of session error: " << text << "; " << info_text;
|
||||
|
||||
QMessageBox msg;
|
||||
msg.setText(text + "\n\n" + info_text);
|
||||
|
@ -547,10 +547,14 @@ void MainWindow::setup_ui()
|
|||
session_selector_.setCornerWidget(static_tab_widget_, Qt::TopLeftCorner);
|
||||
session_selector_.setTabsClosable(true);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this, SLOT(close()));
|
||||
close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), this, SLOT(on_close_current_tab()));
|
||||
#else
|
||||
close_application_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
|
||||
close_application_shortcut_->setAutoRepeat(false);
|
||||
|
||||
close_current_tab_shortcut_ = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this, SLOT(on_close_current_tab()));
|
||||
#endif
|
||||
close_application_shortcut_->setAutoRepeat(false);
|
||||
|
||||
connect(new_session_button_, SIGNAL(clicked(bool)),
|
||||
this, SLOT(on_new_session_clicked()));
|
||||
|
|
|
@ -158,8 +158,13 @@ Channels::Channels(Session &session, QWidget *parent) :
|
|||
layout_.addRow(&filter_buttons_bar_);
|
||||
|
||||
// Connect the check-box signal mapper
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(&check_box_mapper_, SIGNAL(mappedObject(QObject*)),
|
||||
this, SLOT(on_channel_checked(QObject*)));
|
||||
#else
|
||||
connect(&check_box_mapper_, SIGNAL(mapped(QWidget*)),
|
||||
this, SLOT(on_channel_checked(QWidget*)));
|
||||
#endif
|
||||
}
|
||||
|
||||
void Channels::set_all_channels(bool set)
|
||||
|
@ -354,7 +359,11 @@ void Channels::showEvent(QShowEvent *event)
|
|||
updating_channels_ = false;
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void Channels::on_channel_checked(QObject *widget)
|
||||
#else
|
||||
void Channels::on_channel_checked(QWidget *widget)
|
||||
#endif
|
||||
{
|
||||
if (updating_channels_)
|
||||
return;
|
||||
|
|
|
@ -82,7 +82,11 @@ private:
|
|||
void showEvent(QShowEvent *event);
|
||||
|
||||
private Q_SLOTS:
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void on_channel_checked(QObject *widget);
|
||||
#else
|
||||
void on_channel_checked(QWidget *widget);
|
||||
#endif
|
||||
|
||||
void enable_all_channels();
|
||||
void disable_all_channels();
|
||||
|
|
|
@ -130,7 +130,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
|
|||
action_open_->setText(tr("&Open..."));
|
||||
action_open_->setIcon(QIcon::fromTheme("document-open",
|
||||
QIcon(":/icons/document-open.png")));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
action_open_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O));
|
||||
#else
|
||||
action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
|
||||
#endif
|
||||
connect(action_open_, SIGNAL(triggered(bool)),
|
||||
this, SLOT(on_actionOpen_triggered()));
|
||||
|
||||
|
@ -141,7 +145,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
|
|||
action_save_->setText(tr("&Save..."));
|
||||
action_save_->setIcon(QIcon::fromTheme("document-save-as",
|
||||
QIcon(":/icons/document-save-as.png")));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
action_save_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
|
||||
#else
|
||||
action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
#endif
|
||||
connect(action_save_, SIGNAL(triggered(bool)),
|
||||
this, SLOT(on_actionSave_triggered()));
|
||||
|
||||
|
@ -154,7 +162,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view
|
|||
action_save_selection_as_->setText(tr("Save Selected &Range As..."));
|
||||
action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as",
|
||||
QIcon(":/icons/document-save-as.png")));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
|
||||
#else
|
||||
action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
|
||||
#endif
|
||||
connect(action_save_selection_as_, SIGNAL(triggered(bool)),
|
||||
this, SLOT(on_actionSaveSelectionAs_triggered()));
|
||||
|
||||
|
|
|
@ -497,7 +497,11 @@ void QHexView::paintEvent(QPaintEvent *event)
|
|||
painter.setPen(palette().color(QPalette::HighlightedText));
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
painter.drawText(x, y, QString(QChar(ch)));
|
||||
#else
|
||||
painter.drawText(x, y, QString(ch));
|
||||
#endif
|
||||
x += charWidth_;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,11 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
|
|||
save_action_->setText(tr("&Save..."));
|
||||
save_action_->setIcon(QIcon::fromTheme("document-save-as",
|
||||
QIcon(":/icons/document-save-as.png")));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
save_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
|
||||
#else
|
||||
save_action_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
#endif
|
||||
connect(save_action_, SIGNAL(triggered(bool)),
|
||||
this, SLOT(on_actionSave_triggered()));
|
||||
|
||||
|
|
|
@ -202,7 +202,11 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
|
|||
save_action_->setText(tr("&Save..."));
|
||||
save_action_->setIcon(QIcon::fromTheme("document-save-as",
|
||||
QIcon(":/icons/document-save-as.png")));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
save_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
|
||||
#else
|
||||
save_action_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
|
||||
#endif
|
||||
connect(save_action_, SIGNAL(triggered(bool)),
|
||||
this, SLOT(on_actionSave_triggered()));
|
||||
|
||||
|
|
|
@ -1100,13 +1100,20 @@ void AnalogSignal::on_conv_threshold_changed(int index)
|
|||
// https://txt2re.com/index-c++.php3?s=0.1V&1&-13
|
||||
QString re1 = "([+-]?\\d*[\\.,]?\\d*)"; // Float value
|
||||
QString re2 = "([a-zA-Z]*)"; // SI unit
|
||||
QRegExp regex(re1 + re2);
|
||||
|
||||
const QString text = conv_threshold_cb_->currentText();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QRegularExpression regex(re1 + re2);
|
||||
if (!regex.match(text).hasMatch())
|
||||
return; // String doesn't match the regex
|
||||
|
||||
QStringList tokens = regex.match(text).capturedTexts();
|
||||
#else
|
||||
QRegExp regex(re1 + re2);
|
||||
if (!regex.exactMatch(text))
|
||||
return; // String doesn't match the regex
|
||||
|
||||
QStringList tokens = regex.capturedTexts();
|
||||
#endif
|
||||
|
||||
// For now, we simply assume that the unit is volt without modifiers
|
||||
const double thr = tokens.at(1).toDouble();
|
||||
|
@ -1127,13 +1134,22 @@ void AnalogSignal::on_conv_threshold_changed(int index)
|
|||
QString re3 = "\\/"; // Forward slash, not captured
|
||||
QString re4 = "([+-]?\\d*[\\.,]?\\d*)"; // Float value
|
||||
QString re5 = "([a-zA-Z]*)"; // SI unit
|
||||
const QString text = conv_threshold_cb_->currentText();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QRegularExpression regex(re1 + re2 + re3 + re4 + re5);
|
||||
|
||||
if (!regex.match(text).hasMatch())
|
||||
return; // String doesn't match the regex
|
||||
|
||||
QStringList tokens = regex.match(text).capturedTexts();
|
||||
#else
|
||||
QRegExp regex(re1 + re2 + re3 + re4 + re5);
|
||||
|
||||
const QString text = conv_threshold_cb_->currentText();
|
||||
if (!regex.exactMatch(text))
|
||||
return; // String doesn't match the regex
|
||||
|
||||
QStringList tokens = regex.capturedTexts();
|
||||
#endif
|
||||
|
||||
// For now, we simply assume that the unit is volt without modifiers
|
||||
const double low_thr = tokens.at(1).toDouble();
|
||||
|
|
|
@ -186,7 +186,16 @@ DecodeTrace::DecodeTrace(pv::Session &session,
|
|||
this, SLOT(on_decode_finished()));
|
||||
connect(decode_signal_.get(), SIGNAL(channels_updated()),
|
||||
this, SLOT(on_channels_updated()));
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(&delete_mapper_, SIGNAL(mappedInt(int)),
|
||||
this, SLOT(on_delete_decoder(int)));
|
||||
connect(&show_hide_mapper_, SIGNAL(mappedInt(int)),
|
||||
this, SLOT(on_show_hide_decoder(int)));
|
||||
connect(&row_show_hide_mapper_, SIGNAL(mappedInt(int)),
|
||||
this, SLOT(on_show_hide_row(int)));
|
||||
connect(&class_show_hide_mapper_, SIGNAL(mappedObject(QObject*)),
|
||||
this, SLOT(on_show_hide_class(QObject*)));
|
||||
#else
|
||||
connect(&delete_mapper_, SIGNAL(mapped(int)),
|
||||
this, SLOT(on_delete_decoder(int)));
|
||||
connect(&show_hide_mapper_, SIGNAL(mapped(int)),
|
||||
|
@ -195,6 +204,7 @@ DecodeTrace::DecodeTrace(pv::Session &session,
|
|||
this, SLOT(on_show_hide_row(int)));
|
||||
connect(&class_show_hide_mapper_, SIGNAL(mapped(QWidget*)),
|
||||
this, SLOT(on_show_hide_class(QWidget*)));
|
||||
#endif
|
||||
|
||||
connect(&delayed_trace_updater_, SIGNAL(timeout()),
|
||||
this, SLOT(on_delayed_trace_update()));
|
||||
|
@ -667,10 +677,19 @@ void DecodeTrace::mouse_left_press_event(const QMouseEvent* event)
|
|||
continue;
|
||||
|
||||
unsigned int y = get_row_y(&r);
|
||||
if ((event->x() > 0) && (event->x() <= (int)(ArrowSize + 3 + r.title_width)) &&
|
||||
(event->y() > (int)(y - (default_row_height_ / 2))) &&
|
||||
(event->y() <= (int)(y + (default_row_height_ / 2)))) {
|
||||
|
||||
bool need_anim = true;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
need_anim &= event->position().x() > 0;
|
||||
need_anim &= event->position().x() <= (int)(ArrowSize + 3 + r.title_width);
|
||||
need_anim &= event->position().y() > (int)(y - (default_row_height_ / 2));
|
||||
need_anim &= event->position().y() <= (int)(y + (default_row_height_ / 2));
|
||||
#else
|
||||
need_anim &= event->x() > 0;
|
||||
need_anim &= event->x() <= (int)(ArrowSize + 3 + r.title_width);
|
||||
need_anim &= event->y() > (int)(y - (default_row_height_ / 2));
|
||||
need_anim &= event->y() <= (int)(y + (default_row_height_ / 2));
|
||||
#endif
|
||||
if (need_anim) {
|
||||
if (r.expanded) {
|
||||
r.collapsing = true;
|
||||
r.expanded = false;
|
||||
|
@ -1249,6 +1268,19 @@ void DecodeTrace::initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id)
|
|||
QPalette header_palette = owner_->view()->palette();
|
||||
QPalette selector_palette = owner_->view()->palette();
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (GlobalSettings::current_theme_is_dark()) {
|
||||
header_palette.setColor(QPalette::Window,
|
||||
QColor(255, 255, 255, ExpansionAreaHeaderAlpha));
|
||||
selector_palette.setColor(QPalette::Window,
|
||||
QColor(255, 255, 255, ExpansionAreaAlpha));
|
||||
} else {
|
||||
header_palette.setColor(QPalette::Window,
|
||||
QColor(0, 0, 0, ExpansionAreaHeaderAlpha));
|
||||
selector_palette.setColor(QPalette::Window,
|
||||
QColor(0, 0, 0, ExpansionAreaAlpha));
|
||||
}
|
||||
#else
|
||||
if (GlobalSettings::current_theme_is_dark()) {
|
||||
header_palette.setColor(QPalette::Background,
|
||||
QColor(255, 255, 255, ExpansionAreaHeaderAlpha));
|
||||
|
@ -1260,6 +1292,7 @@ void DecodeTrace::initialize_row_widgets(DecodeTraceRow* r, unsigned int row_id)
|
|||
selector_palette.setColor(QPalette::Background,
|
||||
QColor(0, 0, 0, ExpansionAreaAlpha));
|
||||
}
|
||||
#endif
|
||||
|
||||
const int w = m.boundingRect(r->decode_row->title()).width() + RowTitleMargin;
|
||||
r->title_width = w;
|
||||
|
@ -1602,7 +1635,11 @@ void DecodeTrace::on_show_hide_row(int row_id)
|
|||
owner_->row_item_appearance_changed(false, true);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void DecodeTrace::on_show_hide_class(QObject* sender)
|
||||
#else
|
||||
void DecodeTrace::on_show_hide_class(QWidget* sender)
|
||||
#endif
|
||||
{
|
||||
void* ann_class_ptr = sender->property("ann_class_ptr").value<void*>();
|
||||
assert(ann_class_ptr);
|
||||
|
|
|
@ -278,7 +278,11 @@ private Q_SLOTS:
|
|||
|
||||
void on_show_hide_decoder(int index);
|
||||
void on_show_hide_row(int row_id);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
void on_show_hide_class(QObject* sender);
|
||||
#else
|
||||
void on_show_hide_class(QWidget* sender);
|
||||
#endif
|
||||
void on_show_all_classes();
|
||||
void on_hide_all_classes();
|
||||
void on_row_container_resized(QWidget* sender);
|
||||
|
|
|
@ -242,7 +242,11 @@ shared_ptr<ViewItem> Ruler::get_mouse_over_item(const QPoint &pt)
|
|||
|
||||
void Ruler::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
hover_item_ = view_.add_flag(get_absolute_time_from_x_pos(event->pos().x()));
|
||||
#else
|
||||
hover_item_ = view_.add_flag(get_absolute_time_from_x_pos(event->x()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void Ruler::paintEvent(QPaintEvent*)
|
||||
|
|
|
@ -138,7 +138,11 @@ QMenu* TraceGroup::create_header_context_menu(QWidget *parent)
|
|||
QMenu *const menu = new QMenu(parent);
|
||||
|
||||
QAction *const ungroup = new QAction(tr("Ungroup"), this);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
ungroup->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U));
|
||||
#else
|
||||
ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
|
||||
#endif
|
||||
connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup()));
|
||||
menu->addAction(ungroup);
|
||||
|
||||
|
|
|
@ -1530,7 +1530,11 @@ bool View::eventFilter(QObject *object, QEvent *event)
|
|||
else if (object == ruler_)
|
||||
hover_point_ = mouse_event->pos();
|
||||
else if (object == header_)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
hover_point_ = QPoint(0, mouse_event->pos().y());
|
||||
#else
|
||||
hover_point_ = QPoint(0, mouse_event->y());
|
||||
#endif
|
||||
else
|
||||
hover_point_ = QPoint(-1, -1);
|
||||
|
||||
|
|
|
@ -124,12 +124,40 @@ vector< shared_ptr<ViewItem> > Viewport::items()
|
|||
|
||||
bool Viewport::touch_event(QTouchEvent *event)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QList<QEventPoint> touchPoints = event->points();
|
||||
#else
|
||||
QList<QTouchEvent::TouchPoint> touchPoints = event->touchPoints();
|
||||
#endif
|
||||
|
||||
if (touchPoints.count() != 2) {
|
||||
pinch_zoom_active_ = false;
|
||||
return false;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (event->device()->type() == QInputDevice::DeviceType::TouchPad) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QEventPoint &touchPoint0 = touchPoints.first();
|
||||
const QEventPoint &touchPoint1 = touchPoints.last();
|
||||
|
||||
if (!pinch_zoom_active_ ||
|
||||
(event->touchPointStates() & QEventPoint::Pressed)) {
|
||||
pinch_offset0_ = (view_.offset() + view_.scale() * touchPoint0.position().x()).convert_to<double>();
|
||||
pinch_offset1_ = (view_.offset() + view_.scale() * touchPoint1.position().x()).convert_to<double>();
|
||||
pinch_zoom_active_ = true;
|
||||
}
|
||||
|
||||
double w = touchPoint1.position().x() - touchPoint0.position().x();
|
||||
if (abs(w) >= 1.0) {
|
||||
const double scale =
|
||||
fabs((pinch_offset1_ - pinch_offset0_) / w);
|
||||
double offset = pinch_offset0_ - touchPoint0.position().x() * scale;
|
||||
if (scale > 0)
|
||||
view_.set_scale_offset(scale, offset);
|
||||
}
|
||||
#else
|
||||
if (event->device()->type() == QTouchDevice::TouchPad) {
|
||||
return false;
|
||||
}
|
||||
|
@ -152,6 +180,7 @@ bool Viewport::touch_event(QTouchEvent *event)
|
|||
if (scale > 0)
|
||||
view_.set_scale_offset(scale, offset);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (event->touchPointStates() & Qt::TouchPointReleased) {
|
||||
pinch_zoom_active_ = false;
|
||||
|
@ -162,7 +191,11 @@ bool Viewport::touch_event(QTouchEvent *event)
|
|||
} else {
|
||||
// Update the mouse down fields so that continued
|
||||
// dragging with the primary touch will work correctly
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
mouse_down_point_ = touchPoint0.position().toPoint();
|
||||
#else
|
||||
mouse_down_point_ = touchPoint0.pos().toPoint();
|
||||
#endif
|
||||
drag();
|
||||
}
|
||||
}
|
||||
|
@ -215,10 +248,17 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
{
|
||||
assert(event);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
view_.zoom(2.0, event->position().x());
|
||||
else if (event->buttons() & Qt::RightButton)
|
||||
view_.zoom(-2.0, event->position().x());
|
||||
#else
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
view_.zoom(2.0, event->x());
|
||||
else if (event->buttons() & Qt::RightButton)
|
||||
view_.zoom(-2.0, event->x());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Viewport::wheelEvent(QWheelEvent *event)
|
||||
|
|
|
@ -57,7 +57,11 @@ DecoderMenu::DecoderMenu(QWidget *parent, const char* input, bool first_level_de
|
|||
}
|
||||
g_slist_free(li);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(&mapper_, SIGNAL(mappedObject(QObject*)), this, SLOT(on_action(QObject*)));
|
||||
#else
|
||||
connect(&mapper_, SIGNAL(mapped(QObject*)), this, SLOT(on_action(QObject*)));
|
||||
#endif
|
||||
}
|
||||
|
||||
int DecoderMenu::decoder_name_cmp(const void *a, const void *b)
|
||||
|
|
|
@ -55,8 +55,13 @@ DeviceToolButton::DeviceToolButton(QWidget *parent,
|
|||
setDefaultAction(connect_action_);
|
||||
setMinimumWidth(QFontMetrics(font()).averageCharWidth() * 24);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(&mapper_, SIGNAL(mappedObject(QObject*)),
|
||||
this, SLOT(on_action(QObject*)));
|
||||
#else
|
||||
connect(&mapper_, SIGNAL(mapped(QObject*)),
|
||||
this, SLOT(on_action(QObject*)));
|
||||
#endif
|
||||
|
||||
connect(&menu_, SIGNAL(hovered(QAction*)),
|
||||
this, SLOT(on_menu_hovered(QAction*)));
|
||||
|
|
|
@ -75,8 +75,13 @@ ExportMenu::ExportMenu(QWidget *parent, shared_ptr<Context> context,
|
|||
connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(&mapper_, SIGNAL(mappedObject(QObject*)),
|
||||
this, SLOT(on_action(QObject*)));
|
||||
#else
|
||||
connect(&mapper_, SIGNAL(mapped(QObject*)),
|
||||
this, SLOT(on_action(QObject*)));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExportMenu::on_action(QObject *action)
|
||||
|
|
|
@ -146,7 +146,13 @@ QSize FlowLayout::minimumSize() const
|
|||
size.setHeight(h);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
int left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
size += QSize(left + right, top + bottom);
|
||||
#else
|
||||
size += QSize(2 * margin(), 2 * margin());
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -72,8 +72,13 @@ ImportMenu::ImportMenu(QWidget *parent, shared_ptr<Context> context,
|
|||
connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(&mapper_, SIGNAL(mappedObject(QObject*)),
|
||||
this, SLOT(on_action(QObject*)));
|
||||
#else
|
||||
connect(&mapper_, SIGNAL(mapped(QObject*)),
|
||||
this, SLOT(on_action(QObject*)));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImportMenu::on_action(QObject *action)
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
#include <cassert>
|
||||
|
||||
#include <QApplication>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QScreen>
|
||||
#else
|
||||
#include <QDesktopWidget>
|
||||
#endif
|
||||
#include <QLineEdit>
|
||||
#include <QScrollBar>
|
||||
#include <QStyle>
|
||||
|
|
|
@ -54,7 +54,11 @@ SweepTimingWidget::SweepTimingWidget(const char *suffix,
|
|||
this, SIGNAL(value_changed()));
|
||||
|
||||
setLayout(&layout_);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
layout_.setContentsMargins(0, 0, 0, 0);
|
||||
#else
|
||||
layout_.setMargin(0);
|
||||
#endif
|
||||
layout_.addWidget(&list_);
|
||||
layout_.addWidget(&value_);
|
||||
|
||||
|
|
|
@ -20,7 +20,11 @@
|
|||
#include "timestampspinbox.hpp"
|
||||
|
||||
#include <QLineEdit>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QRegularExpression>
|
||||
#else
|
||||
#include <QRegExp>
|
||||
#endif
|
||||
|
||||
namespace pv {
|
||||
namespace widgets {
|
||||
|
@ -93,10 +97,25 @@ void TimestampSpinBox::setValue(const pv::util::Timestamp& val)
|
|||
|
||||
void TimestampSpinBox::on_editingFinished()
|
||||
{
|
||||
QRegExp re(R"(\s*([-+]?)\s*([0-9]+\.?[0-9]*).*)");
|
||||
static const auto re_pattern = R"(\s*([-+]?)\s*([0-9]+\.?[0-9]*).*)";
|
||||
|
||||
if (re.exactMatch(text())) {
|
||||
QStringList captures = re.capturedTexts();
|
||||
bool has_match;
|
||||
QStringList captures;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QRegularExpression re(re_pattern);
|
||||
has_match = re.match(text()).hasMatch();
|
||||
if (has_match) {
|
||||
captures = re.match(text()).capturedTexts();
|
||||
}
|
||||
#else
|
||||
QRegExp re(re_pattern);
|
||||
has_match = re.exactMatch(text());
|
||||
if (has_match) {
|
||||
captures = re.capturedTexts();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (has_match) {
|
||||
captures.removeFirst(); // remove entire match
|
||||
QString str = captures.join("");
|
||||
setValue(pv::util::Timestamp(str.toStdString()));
|
||||
|
|
Loading…
Reference in New Issue