Skip to content

Commit

Permalink
Fixup changeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Feb 21, 2023
1 parent ead8978 commit 192270e
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 107 deletions.
1 change: 1 addition & 0 deletions src/widgets/common/ListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void ListWidget::changeEvent(QEvent *e)
a->setStatusTip(text);
}
}
QWidget::changeEvent(e);
}

void ListWidget::addSeparator(bool invisible)
Expand Down
34 changes: 11 additions & 23 deletions src/widgets/common/OrientationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,33 +151,21 @@ void OrientationWidget::paintGrid(QPainter *p, double radius)
int height = p->fontMetrics().height();
double X = -radius * 0.94;

if(_zeroDirection == North) {
bool condition = ((_zeroDirection == North) || (_zeroDirection == South)) ? value <= 180 : (value >= 90) && (value < 270);

if( (_zeroDirection == North) || (_zeroDirection == West))
p->translate(X, -height);
if (value <= 180) {
p->translate(-X, height);
p->rotate(180);
}
} else if (_zeroDirection == East) {
p->translate(0, 0);

if (_zeroDirection == East)
p->translate(0,0);

if (_zeroDirection == South || _zeroDirection == East)
p->rotate(180);
if (value >= 90 && value < 270) {
p->translate(-X, height);
p->rotate(180);
}
} else if (_zeroDirection == South) {

if(condition) {
p->translate(-X, height);
p->rotate(180);
if (value <= 180) {
p->translate(-X, height);
p->rotate(180);
}
} else if(_zeroDirection == West) {
p->translate(X, -height);
if (value >= 90 && value < 270) {
p->translate(-X, height);
p->rotate(180);
}
}

p->drawText(QRectF(0, 0, radius * 0.9, height), _lblString, QTextOption(Qt::AlignCenter));
}

Expand Down
7 changes: 7 additions & 0 deletions src/widgets/data/AchievementEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
#include <AchievementEditor.h>

#include <QGridLayout>
#include <QEvent>
#include <QListWidget>

void AchievementEditor::changeEvent(QEvent *e)
{
if(e->type() == QEvent::PaletteChange)
achievementList->setStyleSheet(QStringLiteral("QListView::indicator{width: %1px; height:%1px} QListView::item{padding: 0px;}").arg(QString::number(fontMetrics().height())));
QWidget::changeEvent(e);
}
AchievementEditor::AchievementEditor(QWidget *parent) :
QWidget(parent)
{
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/data/AchievementEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private slots:
* \param index QModeIndex from where the change occurred
*/
void itemToggled(const QModelIndex &index);
protected:
void changeEvent(QEvent *e);
private:
void initDisplay(); /**< \brief create this items widgets*/
FF7Achievements achievements; /**< \brief data class for widget*/
Expand Down
19 changes: 13 additions & 6 deletions src/widgets/data/CharEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ CharEditor::CharEditor(QWidget *parent)

void CharEditor::changeEvent(QEvent *e)
{
if (e->type() != QEvent::LanguageChange) {
QWidget::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
updateText();
} else if(e->type() == QEvent::PaletteChange) {
weapon_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0}"));
armor_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0}"));
accessory_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0}"));
for(auto m : materiaSlotFrames) {
m->setStyleSheet(QStringLiteral("QFrame{background-color:rgba(0,0,0,0);}"));
}
}
updateText();
QWidget::changeEvent(e);
}

void CharEditor::updateText()
Expand Down Expand Up @@ -656,7 +663,7 @@ void CharEditor::init_display()
weapon_materia_box->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

weapon_selection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
weapon_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0;}"));
weapon_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0}"));

auto weapon_layout = new QVBoxLayout;
weapon_layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -686,7 +693,7 @@ void CharEditor::init_display()
armor_materia_box->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

armor_selection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
armor_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0;}"));
armor_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0}"));

auto armor_layout = new QVBoxLayout;
armor_layout->setContentsMargins(0, 0, 0, 0);
Expand All @@ -697,7 +704,7 @@ void CharEditor::init_display()
armor_box->setLayout(armor_layout);

accessory_selection->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
accessory_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0;}"));
accessory_selection->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0}"));

auto accessory_layout = new QVBoxLayout;
accessory_layout->setContentsMargins(0, 0, 0, 0);
Expand Down
8 changes: 5 additions & 3 deletions src/widgets/data/ChocoboEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,10 @@ QSpinBox *ChocoboEditor::makeSpinBox(int maxValue)

void ChocoboEditor::changeEvent(QEvent *e)
{
if (e->type() != QEvent::LanguageChange) {
QWidget::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
updateText();
} else if (e->type() == QEvent::PaletteChange) {
cb_cantMate->setStyleSheet(QStringLiteral("QCheckBox::indicator {width: %1px; height: %1px;}").arg(QString::number(fontMetrics().height())));
}
updateText();
QWidget::changeEvent(e);
}
42 changes: 26 additions & 16 deletions src/widgets/data/ChocoboLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,30 @@

bool ChocoboLabel::event(QEvent *ev)
{
if(ev->type() == QEvent::PaletteChange) {
setHoverColorStyle(QStringLiteral("rgba(%1,%2,%3,128);")
.arg(QString::number(palette().highlight().color().red())
, QString::number(palette().highlight().color().green())
, QString::number(palette().highlight().color().blue())));
return true;
} else if (ev->type() == QEvent::MouseButtonPress && isEnabled) {
if (ev->type() == QEvent::MouseButtonPress && isEnabled) {
Q_EMIT clicked();
return true;
} else if (ev->type() == QEvent::LanguageChange) {
}
return QWidget::event(ev);
}

void ChocoboLabel::changeEvent(QEvent *e)
{
if(e->type() == QEvent::PaletteChange) {
setHoverColorStyle(QStringLiteral("rgba(%1,%2,%3,128);")
.arg(QString::number(palette().highlight().color().red())
, QString::number(palette().highlight().color().green())
, QString::number(palette().highlight().color().blue())));
chkOccupied->setProperty("HoverStyled", QVariant(true));
chkOccupied->setStyleSheet(QStringLiteral("QCheckBox{ padding: 1px;} QCheckBox::indicator{width: %1px; height: %1px;}").arg(QString::number(fontMetrics().height())));
setSelected(isSelected);
} else if (e->type() == QEvent::LanguageChange) {
btnCopy->setToolTip(QString(tr("Copy")));
btnPaste->setToolTip(QString(tr("Paste")));
btnRemove->setToolTip(QString(tr("Remove")));
setRank(m_wins);
return true;
} else {
return false;
}
QWidget::changeEvent(e);
}

ChocoboLabel::ChocoboLabel(const QString &titleText, bool occupied, QWidget *parent) :
Expand Down Expand Up @@ -232,11 +238,14 @@ void ChocoboLabel::clearLabel()

void ChocoboLabel::setFontSize(int fontSize)
{
QString fontStyle = QString("font-size:%1pt;background-color:rgba(0,0,0,0);").arg(fontSize);
lblName->setStyleSheet(fontStyle);
lblSex->setStyleSheet(fontStyle);
lblRank->setStyleSheet(fontStyle);
lblType->setStyleSheet(fontStyle);
if(m_fontSize != fontSize)
m_fontSize = fontSize;
auto fnt = lblName->font();
fnt.setPointSize(fontSize);
lblName->setFont(fnt);
lblSex->setFont(fnt);
lblRank->setFont(fnt);
lblType->setFont(fnt);
}

void ChocoboLabel::enable(bool enabled)
Expand All @@ -250,6 +259,7 @@ void ChocoboLabel::enable(bool enabled)

void ChocoboLabel::setSelected(bool selected)
{
isSelected = selected;
if (selected) {
outerFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); innerFrame->setStyleSheet(SelectedBkStyle);
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/widgets/data/ChocoboLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ public slots:
void clearLabel(void); /**< \brief Clear the labels data */
void setHoverColorStyle(QString backgroundColor); /**< \brief Set the style for when you hover \param backgroundColor A valid color for a style sheet either a predefined color or rgb(r,g,b) style string */
bool isOccupied(void); /**< \brief occupied state \return true if occupied*/
protected:
bool event(QEvent *ev);
void changeEvent(QEvent *e);
private:
void enable(bool enabled); /**< \brief enable/disable inner part of the form when needed \param enabled enable the lower frame?*/
bool event(QEvent *ev);
QPushButton *btnCopy = nullptr; /**< \brief copy button */
QPushButton *btnPaste = nullptr; /**< \brief paste button */
QPushButton *btnRemove = nullptr; /**< \brief remove button */
Expand All @@ -74,5 +76,7 @@ public slots:
QFrame *outerFrame = nullptr;/**< \brief outer frame of widget contains the label checkbox, copy,paste,remove buttons*/
QString SelectedBkStyle;/**< \brief style for background when selected */
int m_wins = -1;
int m_fontSize = 14;
bool isSelected;
bool isEnabled; /**< \brief isEnabled hold if enabled */
};
58 changes: 30 additions & 28 deletions src/widgets/data/ChocoboManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@

void ChocoboManager::changeEvent(QEvent *e)
{
if (e->type() != QEvent::LanguageChange) {
QWidget::changeEvent(e);
}

lblStablesOwned ->setText(tr("Stables Owned"));
lblStablesOccupied->setText(tr("Stables Occupied"));
penBox->setTitle(tr("Fenced Chocobos"));
updateCombos();
for (int i = 0; i < 6; i++) {
chocoboLabel[i]->setTitle(tr("Stable:%1").arg(QString::number(i + 1)));
}
if (e->type() == QEvent::LanguageChange) {
lblStablesOwned ->setText(tr("Stables Owned"));
lblStablesOccupied->setText(tr("Stables Occupied"));
penBox->setTitle(tr("Fenced Chocobos"));
updateCombos();
for (int i = 0; i < 6; i++)
chocoboLabel[i]->setTitle(tr("Stable:%1").arg(QString::number(i + 1)));
} else if(e->type() == QEvent::PaletteChange) {
QString color = QStringLiteral("%1,%2,%3").arg(palette().highlight().color().red(), palette().highlight().color().green(), palette().highlight().color().blue());
for (int i = 0; i < 6; i++)
chocoboLabel[i]->setHoverColorStyle(color);
}
QWidget::changeEvent(e);
}

ChocoboManager::ChocoboManager(QWidget *parent) :
Expand Down Expand Up @@ -97,25 +99,25 @@ ChocoboManager::ChocoboManager(QWidget *parent) :

void ChocoboManager::setStablesOwned(int value)
{
if (value == stablesOwned) {
if (value == stablesOwned)
return;
} else if (value < 0 || value > 6) {

if ((value < 0) || (value > 6))
return;
} else {
disableChocoLabels();
enableChocoboLabels(value);
stablesOwned = qint8(value);
Q_EMIT ownedChanged(qint8(value));
for (int i = value; i < 6 ; i++) {
if (chocoboLabel[i]->isOccupied()) {
chocoboLabel[i]->setOccupied(false);
setOccupied(stablesOccupied - 1, stableMask &= ~(1 << i));
Q_EMIT occupiedChanged(stablesOccupied);
Q_EMIT stableMaskChanged(stableMask);
if (i == selectedStable) {
selectedStable = -1;
chocoboEditor->setHidden(true);
}

disableChocoLabels();
enableChocoboLabels(value);
stablesOwned = qint8(value);
Q_EMIT ownedChanged(qint8(value));
for (int i = value; i < 6 ; i++) {
if (chocoboLabel[i]->isOccupied()) {
chocoboLabel[i]->setOccupied(false);
setOccupied(stablesOccupied - 1, stableMask &= ~(1 << i));
Q_EMIT occupiedChanged(stablesOccupied);
Q_EMIT stableMaskChanged(stableMask);
if (i == selectedStable) {
selectedStable = -1;
chocoboEditor->setHidden(true);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/data/ItemList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void ItemList::destroySelector()
}
void ItemList::changeEvent(QEvent *e)
{
if (e->type() != QEvent::LanguageChange)
QTableWidget::changeEvent(e);
itemupdate();
if (e->type() == QEvent::LanguageChange)
itemupdate();
QTableWidget::changeEvent(e);
}

ItemList::ItemList(QWidget *parent)
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/data/LocationViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ void LocationViewer::resizeEvent(QResizeEvent *ev)

void LocationViewer::changeEvent(QEvent *e)
{
if (e->type() != QEvent::LanguageChange) {
QWidget::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
updateText();
}
updateText();
QWidget::changeEvent(e);
}

void LocationViewer::updateText()
Expand Down
60 changes: 39 additions & 21 deletions src/widgets/data/MateriaEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,27 +503,45 @@ QWidget *MateriaEditor::makeStarWidget()
}
void MateriaEditor::changeEvent(QEvent *e)
{
if (e->type() != QEvent::LanguageChange)
QWidget::changeEvent(e);

updateESkillList();
box_skills->setTitle(tr("Skills"));
box_status_effects->setTitle(tr("Added Effect"));
box_stats->setTitle(tr("Stat Changes"));
btn_rm_materia->setToolTip(tr("Delete"));
btn_paste_materia->setToolTip(tr("Paste"));
btn_copy_materia->setToolTip(tr("Copy"));
btn_eskill_master->setText(tr("Master"));
btn_eskill_clear->setText(tr("Clear"));
combo_type->setItemText(0, tr("All Materia"));
combo_type->setItemText(1, tr("Magic"));
combo_type->setItemText(2, tr("Summon"));
combo_type->setItemText(3, tr("Independent"));
combo_type->setItemText(4, tr("Support"));
combo_type->setItemText(5, tr("Command"));
typeChanged(combo_type->currentIndex());
setStats();
setSkills();
qDebug() << "materia_event" << e->type();
if (e->type() == QEvent::LanguageChange) {
updateESkillList();
box_skills->setTitle(tr("Skills"));
box_status_effects->setTitle(tr("Added Effect"));
box_stats->setTitle(tr("Stat Changes"));
btn_rm_materia->setToolTip(tr("Delete"));
btn_paste_materia->setToolTip(tr("Paste"));
btn_copy_materia->setToolTip(tr("Copy"));
btn_eskill_master->setText(tr("Master"));
btn_eskill_clear->setText(tr("Clear"));
combo_type->setItemText(0, tr("All Materia"));
combo_type->setItemText(1, tr("Magic"));
combo_type->setItemText(2, tr("Summon"));
combo_type->setItemText(3, tr("Independent"));
combo_type->setItemText(4, tr("Support"));
combo_type->setItemText(5, tr("Command"));
typeChanged(combo_type->currentIndex());
setStats();
setSkills();
} else if (e->type() == QEvent::PaletteChange) {
combo_materia->setStyleSheet(QStringLiteral("QComboBox { combobox-popup: 0;}"));
QString emptyColor = QStringLiteral("0,0,0,0");
_highlightColor = QStringLiteral("%1,%2,%3,128").arg(QString::number(palette().highlight().color().red()), QString::number(palette().highlight().color().green()), QString::number(palette().highlight().color().blue()));
btn_rm_materia->setStyleSheet(_buttonStyle.arg(_highlightColor));
btn_copy_materia->setStyleSheet(_buttonStyle.arg(_highlightColor));
btn_paste_materia->setStyleSheet(_buttonStyle.arg(_highlightColor));
if(_editable) {
eskill_list->setStyleSheet(_itemStyle.arg(_highlightColor, QString::number(fontMetrics().height())));
for (QPushButton *button : qAsConst(btn_stars))
button->setStyleSheet(_buttonStyle.arg(_highlightColor));
}
else {
eskill_list->setStyleSheet(_itemStyle.arg(emptyColor, QString::number(fontMetrics().height())));
for (QPushButton *button : qAsConst(btn_stars))
button->setStyleSheet(_buttonStyle.arg(emptyColor));
}
}
QWidget::changeEvent(e);
}
void MateriaEditor::updateESkillList()
{
Expand Down
Loading

0 comments on commit 192270e

Please sign in to comment.