Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More qt6 porting #2622

Merged
merged 17 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5b29337
Port QColor::setNamedColor to QColor::fromString
ctrlaltca Mar 20, 2024
cb83639
Port from QVariant::Type to QmetaType::Type
ctrlaltca Mar 20, 2024
bbc38e2
KviCoreActions: port from QAction::parentWidget to qobject_cast + QAc…
ctrlaltca Mar 20, 2024
ebcf473
KviIrcView: port QString::fromUtf16 usage to the non-obsolete char16_…
ctrlaltca Mar 20, 2024
1b3b810
KviTopicWidget: port QMouseEvent to a non-obsolete overload
ctrlaltca Mar 20, 2024
96286e0
Port QMouseEvent from old pos(), x(), y(), to position()
ctrlaltca Mar 20, 2024
de4546d
Port obsolete QMessageBox usage to custom buttons
ctrlaltca Mar 20, 2024
e86b089
KviApplication: initialize the dbus notify message "replace ID" to 0
ctrlaltca Mar 20, 2024
f903081
KviIrcConnection: port deprecated QString::count() to QString::size()
ctrlaltca Mar 20, 2024
7c19e2c
KvsObject_*: port QColor::setNamedColor to QColor::fromString
ctrlaltca Mar 20, 2024
4163837
KvsObject_widget: port QWidget::isTopLevel to QWidget::isWindow
ctrlaltca Mar 20, 2024
a554f9d
KviMainWindow: use QKeyCombination instead of int for shortcuts
ctrlaltca Mar 21, 2024
b2a4edc
QHttp: avoid deprecated methods for QCryptographicHash
ctrlaltca Mar 21, 2024
5f44187
ScriptEditorWidget: use the new signature for QMenu::addAction()
ctrlaltca Mar 21, 2024
69e9e20
KviInputEditor: Extract ACCEL_KEY from header and avoid warning
ctrlaltca Mar 21, 2024
6f5ad1f
KviStringConversion: convert old Qt5 font weights to new "css" font w…
ctrlaltca Mar 21, 2024
a54359d
syntax fix
ctrlaltca Mar 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions src/kvilib/ext/KviStringConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QString>
#include <QStringList>
#include <cstdio>
#include <array>

QString g_szGlobalDir;
QString g_szLocalDir;
Expand Down Expand Up @@ -219,7 +220,11 @@ namespace KviStringConversion

bool fromString(const QString & szValue, QColor & buffer)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))
buffer.setNamedColor(szValue);
#else
buffer = QColor::fromString(szValue);
#endif
return true;
}

Expand All @@ -238,15 +243,37 @@ namespace KviStringConversion
if(font.fixedPitch())
szOptions.append('f');

szBuffer = QString::asprintf("%s,%d,%d,%d,%s,%s", szFamily.toUtf8().data(), font.pointSize(), font.styleHint(),
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
font.weight(),
#else
font.legacyWeight(),
#endif
szOptions.toUtf8().data(),
font.styleName().toUtf8().data()
);
szBuffer = QString::asprintf("%s,%d,%d,%d,%s,%s", szFamily.toUtf8().data(), font.pointSize(), font.styleHint(), font.weight(), szOptions.toUtf8().data(), font.styleName().toUtf8().data());
}

/* Helper function to convert Qt < 6.0 font weight to OpenType font weight */
static int fromLegacyWeight(int weight)
{
static constexpr std::array<int, 2> weightMap[] = {
{ 0, QFont::Thin },
{ 12, QFont::ExtraLight },
{ 25, QFont::Light },
{ 50, QFont::Normal },
{ 57, QFont::Medium },
{ 63, QFont::DemiBold },
{ 75, QFont::Bold },
{ 81, QFont::ExtraBold },
{ 87, QFont::Black },
};

int closestDist = INT_MAX;
int result = -1;
for (auto item: weightMap) {
const int dist = qAbs(item[0] - weight);
if (dist < closestDist) {
result = item[1];
closestDist = dist;
} else {
break;
}
}

return result;
}

bool fromString(const QString & szValue, QFont & buffer)
Expand All @@ -269,12 +296,21 @@ namespace KviStringConversion
if(bOk && (i >= 0))
buffer.setStyleHint((QFont::StyleHint)i);
i = weight.toInt(&bOk);
if(bOk && (i >= 0))
if(bOk && (i >= 0)) {
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
buffer.setWeight(i);
#else
buffer.setLegacyWeight(i);
/*
* KVIrc <= 5.2.2 used Qt5 font weights (0 = thinner, 99 = bolder)
* Qt6 introduced opentype (css) font weight (100 = thinner, 900 = bolder)
* if the config is using an old weight, convert it
*/
if(i < 100) {
i = KviStringConversion::fromLegacyWeight(i);
}
buffer.setWeight(QFont::Weight(i));
#endif
}
buffer.setBold(options.contains("b"));
buffer.setItalic(options.contains("i"));
buffer.setUnderline(options.contains("u"));
Expand Down
93 changes: 55 additions & 38 deletions src/kvirc/kernel/KviApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ void KviApplication::notifierMessage(KviWindow * pWnd, int iIconId, const QStrin
// org.freedesktop.Notifications.Notify
QVariantList args;
args << QString("KVIrc"); // application name
args << QVariant(QVariant::UInt); // notification id
args << QVariant(0); // notification id
args << szIcon; // application icon
args << szTitle; // summary text
args << szText; // detailed text
Expand Down Expand Up @@ -980,26 +980,35 @@ void KviApplication::checkSuggestRestoreDefaultScript()
// first: check if the user configuration has ever been updated to the current version
if(!KviDefaultScriptManager::instance()->isDefscriptUpToDate())
{
switch(
QMessageBox::question(nullptr, __tr2qs("Update Default Scripts - KVIrc"),
__tr2qs("<b>Your KVirc installation has been updated successfully.</b><br><br>"
"KVIrc's default scripts should also be updated. "
"<b>Do you want to restore the default scripts?</b><br><br>"
"Hint: If you choose \"No\" you can always restore the "
"default scripts by selecting the appropriate entry from the \"Scripting\" menu later."),
__tr2qs("No and Don't Ask Me Again"), __tr2qs("No"), __tr2qs("Yes"), 1, 1))
QMessageBox msg(nullptr);
msg.setIcon(QMessageBox::Question);
msg.setWindowTitle(__tr2qs("Update Default Scripts - KVIrc"));
msg.setText(__tr2qs("<b>Your KVirc installation has been updated successfully.</b><br><br>"
"KVIrc's default scripts should also be updated. "
"<b>Do you want to restore the default scripts?</b><br><br>"
"Hint: If you choose \"No\" you can always restore the "
"default scripts by selecting the appropriate entry from the \"Scripting\" menu later."));
QPushButton * neverButton = msg.addButton(__tr2qs("No and Don't Ask Me Again"), QMessageBox::NoRole);
QPushButton * noButton = msg.addButton(__tr2qs("No"), QMessageBox::NoRole);
QPushButton * yesButton = msg.addButton(__tr2qs("Yes"), QMessageBox::YesRole);
msg.setDefaultButton(noButton);
msg.setEscapeButton(noButton);
msg.exec();

if(msg.clickedButton() == neverButton)
{
case 0:
KVI_OPTION_BOOL(KviOption_boolDoNotSuggestRestoreDefaultScript) = true;
return;
break;
case 1:
// we want to execute the next checks, don't return now
break;
default:
restoreDefaultScript();
// we want to execute the next checks after the attempted restore, don't return now
break;
KVI_OPTION_BOOL(KviOption_boolDoNotSuggestRestoreDefaultScript) = true;
return;
}
else if(msg.clickedButton() == yesButton)
{
restoreDefaultScript();
// we want to execute the next checks after the attempted restore, don't return now
}
else
{
// "no button" or no button cliecked
// we want to execute the next checks, don't return now
}
}

Expand Down Expand Up @@ -1044,25 +1053,33 @@ void KviApplication::checkSuggestRestoreDefaultScript()

bSuggestedOnce = true;

switch(
QMessageBox::question(nullptr, __tr2qs("Detected Installation Issues - KVIrc"),
__tr2qs("<b>Your KVIrc installation is incomplete.</b><br><br>"
"You seem to be missing some of the features that the KVIrc default scripts provide. "
"<b>Do you want to restore the default scripts?</b><br><br>"
"Hint: If you choose \"No\" you can always restore the "
"default scripts by selecting the appropriate entry from the \"Scripting\" menu later."),
__tr2qs("No and Don't Ask Me Again"), __tr2qs("No"), __tr2qs("Yes"), 1, 1))
QMessageBox msg(nullptr);
msg.setIcon(QMessageBox::Question);
msg.setWindowTitle(__tr2qs("Detected Installation Issues - KVIrc"));
msg.setText(__tr2qs("<b>Your KVIrc installation is incomplete.</b><br><br>"
"You seem to be missing some of the features that the KVIrc default scripts provide. "
"<b>Do you want to restore the default scripts?</b><br><br>"
"Hint: If you choose \"No\" you can always restore the "
"default scripts by selecting the appropriate entry from the \"Scripting\" menu later."));
QPushButton * neverButton = msg.addButton(__tr2qs("No and Don't Ask Me Again"), QMessageBox::NoRole);
QPushButton * noButton = msg.addButton(__tr2qs("No"), QMessageBox::NoRole);
QPushButton * yesButton = msg.addButton(__tr2qs("Yes"), QMessageBox::YesRole);
msg.setDefaultButton(noButton);
msg.setEscapeButton(noButton);
msg.exec();

if(msg.clickedButton() == neverButton)
{
case 0:
KVI_OPTION_BOOL(KviOption_boolDoNotSuggestRestoreDefaultScript) = true;
return;
break;
case 1:
return;
break;
default:
restoreDefaultScript();
break;
KVI_OPTION_BOOL(KviOption_boolDoNotSuggestRestoreDefaultScript) = true;
return;
}
else if(msg.clickedButton() == yesButton)
{
restoreDefaultScript();
}
else
{
// "no button" or no button cliecked
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/kvirc/kernel/KviCoreActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void KviIrcContextDisplayAction::activeContextChanged()
{
for(auto & pAction : m_pActionList)
{
QToolBar * t = (QToolBar *)pAction->parentWidget();
QToolBar * t = qobject_cast<QToolBar *>(pAction->parent());
if(t)
{
KviIrcContextDisplay * w = (KviIrcContextDisplay *)t->widgetForAction(pAction);
Expand All @@ -478,7 +478,7 @@ void KviIrcContextDisplayAction::activeContextStateChanged()
{
for(auto & pAction : m_pActionList)
{
QToolBar * t = (QToolBar *)pAction->parentWidget();
QToolBar * t = qobject_cast<QToolBar *>(pAction->parent());
if(t)
{
KviIrcContextDisplay * w = (KviIrcContextDisplay *)t->widgetForAction(pAction);
Expand Down
2 changes: 1 addition & 1 deletion src/kvirc/kernel/KviIrcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ void KviIrcConnection::joinChannels(const std::vector<std::pair<QString, QString
[](const std::pair<QString, QString> & left,
const std::pair<QString, QString> & right)
{
return left.second.count() > right.second.count();
return left.second.size() > right.second.size();
});

// We send the channel list in chunks to avoid overflowing the 510 character limit on the message.
Expand Down
Loading
Loading