Add Qt 5.9 compatibility (#202)

* Added Ubuntu 18 backwards compatibility

Co-authored-by: Cents02 <Cents02@Cents0.me>
This commit is contained in:
windrammer 2020-07-29 16:43:33 -06:00 committed by GitHub
parent 949a323903
commit abe80513d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 9 deletions

View File

@ -11,8 +11,11 @@ void AOLineEdit::mouseDoubleClickEvent(QMouseEvent *e)
void AOLineEdit::focusOutEvent(QFocusEvent *ev)
{
int start = selectionStart();
int len = selectionEnd() - start; // We're not using selectionLength because
// Linux build doesn't run qt5.10
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
int len = selectionLength();
#else
int len = selectedText().length();
#endif
QLineEdit::focusOutEvent(ev);
if (p_selection && start != -1 && len != -1)
this->setSelection(start, len);

View File

@ -1903,8 +1903,12 @@ void Courtroom::handle_chatmessage_2()
ui_vp_chatbox->set_image("chatbox");
QFontMetrics fm(ui_vp_showname->font());
// Gotta support the slow paced ubuntu 18 STUCK IN 5.9.5!!
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
int fm_width = fm.horizontalAdvance(ui_vp_showname->text());
#else
int fm_width = fm.boundingRect((ui_vp_showname->text())).width();
#endif
QString chatbox_path = ao_app->get_theme_path("chat");
QString chatbox = ao_app->get_chat(m_chatmessage[CHAR_NAME]);
QString customchar;
@ -1917,7 +1921,8 @@ void Courtroom::handle_chatmessage_2()
ui_vp_chatbox->set_chatbox(chatbox_path + "box");
}
//This should probably be called only if any change from the last chat arrow was actually detected.
// This should probably be called only if any change from the last chat
// arrow was actually detected.
pos_size_type design_ini_result = ao_app->get_element_dimensions(
"chat_arrow", "courtroom_design.ini", customchar);
if (design_ini_result.width < 0 || design_ini_result.height < 0) {
@ -3051,11 +3056,13 @@ void Courtroom::handle_song(QStringList *p_contents)
(f_song_clear.lastIndexOf("/") + 1));
int n_char = f_contents.at(1).toInt();
//Assume the song doesn't loop unless told otherwise (due to most outdated servers handling looping through serverside)
// Assume the song doesn't loop unless told otherwise (due to most outdated
// servers handling looping through serverside)
bool looping = false;
//Channel 0 is the 'master music', other channels would commonly be used for ambience
// Channel 0 is the 'master music', other channels would commonly be used for
// ambience
int channel = 0;
//No effects assumed by default - vanilla functionality
// No effects assumed by default - vanilla functionality
int effect_flags = 0;
if (n_char < 0 || n_char >= char_list.size()) {
@ -4340,7 +4347,12 @@ void Courtroom::on_text_color_changed(int p_color)
if (markdown_end.isEmpty())
markdown_end = markdown_start;
int start = ui_ic_chat_message->selectionStart();
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
int end = ui_ic_chat_message->selectionEnd() + 1;
#else
int end = ui_ic_chat_message->selectedText().length() + 1;
#endif
ui_ic_chat_message->setCursorPosition(start);
ui_ic_chat_message->insert(markdown_start);
ui_ic_chat_message->setCursorPosition(end);

View File

@ -3,7 +3,7 @@
#include <QDebug>
#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
#if (defined(_WIN32) || defined(_WIN64))
#include <windows.h>

View File

@ -34,8 +34,12 @@ void ScrollText::setSeparator(QString separator)
void ScrollText::updateText()
{
timer.stop();
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
singleTextWidth = fontMetrics().horizontalAdvance(_text);
#else
singleTextWidth = fontMetrics().boundingRect(_text).width();
#endif
scrollEnabled = (singleTextWidth > width() - leftMargin * 2);
if (scrollEnabled) {
@ -47,8 +51,14 @@ void ScrollText::updateText()
staticText.setText(_text);
staticText.prepare(QTransform(), font());
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
wholeTextSize = QSize(fontMetrics().horizontalAdvance(staticText.text()),
fontMetrics().height());
#else
wholeTextSize = QSize(fontMetrics().boundingRect(staticText.text()).width(),
fontMetrics().height());
#endif
}
void ScrollText::paintEvent(QPaintEvent *)