Commit c001fdee authored by Michael Reeves's avatar Michael Reeves

Use Qt signaling to relay encoding change

Eliminates the need for EncodingLabel to talk directly with DiffTextWindowFrame
parent 0bdde6bc
......@@ -1778,7 +1778,8 @@ DiffTextWindowFrame::DiffTextWindowFrame(QWidget* pParent, QStatusBar* pStatusBa
pHL2->setMargin(0);
pHL2->setSpacing(2);
pHL2->addWidget(d->m_pTopLine, 0);
d->m_pEncoding = new EncodingLabel(i18n("Encoding:"), this, psd, pOptions);
d->m_pEncoding = new EncodingLabel(i18n("Encoding:"), psd, pOptions);
connect((EncodingLabel*) d->m_pEncoding, &EncodingLabel::encodingChanged, this, &DiffTextWindowFrame::slotEncodingChanged);
d->m_pLineEndStyle = new QLabel(i18n("Line end style:"));
pHL2->addWidget(d->m_pEncoding);
......@@ -1908,15 +1909,9 @@ void DiffTextWindowFrame::slotBrowseButtonClicked()
}
}
void DiffTextWindowFrame::sendEncodingChangedSignal(QTextCodec* c)
{
emit encodingChanged(c);
}
EncodingLabel::EncodingLabel(const QString& text, DiffTextWindowFrame* pDiffTextWindowFrame, SourceData* pSD, Options* pOptions)
EncodingLabel::EncodingLabel(const QString& text, SourceData* pSD, Options* pOptions)
: QLabel(text)
{
m_pDiffTextWindowFrame = pDiffTextWindowFrame;
m_pOptions = pOptions;
m_pSourceData = pSD;
m_pContextEncodingMenu = nullptr;
......@@ -1990,12 +1985,12 @@ void EncodingLabel::insertCodec(const QString& visibleCodecName, QTextCodec* pCo
if(currentTextCodecEnum == CodecMIBEnum)
pAction->setChecked(true);
pMenu->addAction(pAction);
connect(pAction, &QAction::triggered, this, &EncodingLabel::slotEncodingChanged);
connect(pAction, &QAction::triggered, this, &EncodingLabel::slotSelectEncoding);
codecEnumList.append(CodecMIBEnum);
}
}
void EncodingLabel::slotEncodingChanged()
void EncodingLabel::slotSelectEncoding()
{
QAction* pAction = qobject_cast<QAction*>(sender());
if(pAction)
......@@ -2015,6 +2010,7 @@ void EncodingLabel::slotEncodingChanged()
recentEncodings.append(s);
}
}
m_pDiffTextWindowFrame->sendEncodingChangedSignal(pCodec);
emit encodingChanged(pCodec);
}
}
......@@ -116,7 +116,6 @@ public:
DiffTextWindow* getDiffTextWindow();
void init();
void setFirstLine(int firstLine);
void sendEncodingChangedSignal(QTextCodec* c);
Q_SIGNALS:
void fileNameChanged(const QString&, e_SrcSelector);
void encodingChanged(QTextCodec*);
......@@ -126,7 +125,7 @@ protected:
private Q_SLOTS:
void slotReturnPressed();
void slotBrowseButtonClicked();
void slotEncodingChanged(QTextCodec* c) { emit encodingChanged(c); };//relay signal from encoding label
private:
DiffTextWindowFrameData* d;
};
......@@ -135,14 +134,15 @@ class EncodingLabel : public QLabel
{
Q_OBJECT
public:
EncodingLabel( const QString & text, DiffTextWindowFrame* pDiffTextWindowFrame, SourceData* psd, Options* pOptions);
EncodingLabel( const QString & text, SourceData* psd, Options* pOptions);
protected:
void mouseMoveEvent(QMouseEvent *ev) override;
void mousePressEvent(QMouseEvent *ev) override;
Q_SIGNALS:
void encodingChanged(QTextCodec*);
private Q_SLOTS:
void slotEncodingChanged();
void slotSelectEncoding();
private:
DiffTextWindowFrame* m_pDiffTextWindowFrame; //To send "EncodingChanged" signal
QMenu* m_pContextEncodingMenu;
SourceData* m_pSourceData; //SourceData to get access to "isEmpty()" and "isFromBuffer()" functions
static const int m_maxRecentEncodings = 5;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment