Skip to content

Commit

Permalink
fixup! Crash and UI issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaopengLin committed Sep 13, 2024
1 parent f4ad9f8 commit 6937c65
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
41 changes: 36 additions & 5 deletions resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,59 @@ ContentTypeFilter {
#readinglistbar QPushButton::menu-indicator {
width: 0;
height: 0;

}
/* ----------------------------------------
Text to Speech Page
*/

#TextToSpeechBar {
TextToSpeechBar {
border-top: 1px solid #ccc;
}

TextToSpeechBar > #closeButton {
TextToSpeechBar #closeButton {
outline: none;
max-height: 36px;
max-width: 36px;
border: 1px solid #ccc;
border-radius: 0;
}

TextToSpeechBar > #closeButton:pressed {
TextToSpeechBar #stopButton {
outline: none;
max-height: 36px;
padding-left: 10px;
padding-right: 10px;
border: 1px solid #ccc;
background-color: white;
border-radius: 0;
}

TextToSpeechBar #stopButton:hover {
background-color: #D9E9FF;
border: 1px solid #3366CC;
}

TextToSpeechBar > #stopButton:disabled {
TextToSpeechBar #stopButton:disabled {
color: grey;
background-color: darkgrey;
}

TextToSpeechBar QComboBox::drop-down {
image: url(":/icons/search_forward.svg");
background-color: white;
}

TextToSpeechBar QComboBox {
background-color: white;
border: 1px solid #ccc;
}

TextToSpeechBar QComboBox QAbstractItemView QScrollBar {
width: 5px;
border: none;
outline: none;
}

TextToSpeechBar QComboBox QAbstractItemView QScrollBar::handle {
background-color: grey;
}
20 changes: 11 additions & 9 deletions src/texttospeechbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include "ui_texttospeechbar.h"
#include <QDebug>

QTextToSpeech TextToSpeechBar::m_speech;
TextToSpeechBar::TextToSpeechBar(QWidget *parent)
: QFrame(parent), mp_speech(new QTextToSpeech(this)),
: QFrame(parent),
mp_ui(new Ui::TextToSpeechBar)
{
close();
mp_ui->setupUi(this);
mp_ui->stopButton->setText(gt("stop"));
mp_ui->voiceLabel->setText(gt("voice"));
connect(mp_speech, &QTextToSpeech::stateChanged, this,
connect(&m_speech, &QTextToSpeech::stateChanged, this,
&TextToSpeechBar::onStateChanged);
connect(mp_ui->stopButton, &QPushButton::released, this,
&TextToSpeechBar::stop);
Expand All @@ -21,7 +22,7 @@ TextToSpeechBar::TextToSpeechBar(QWidget *parent)
mp_ui->langLabel->setText(gt("language"));
mp_ui->langComboBox->setMaxVisibleItems(10);
QLocale current = QLocale::system().language();
for (auto locale : mp_speech->availableLocales())
for (auto locale : m_speech.availableLocales())
{
QString name(QString("%1 (%2)")
.arg(QLocale::languageToString(locale.language()))
Expand All @@ -44,12 +45,12 @@ TextToSpeechBar::TextToSpeechBar(QWidget *parent)

void TextToSpeechBar::speak(const QString &text)
{
mp_speech->say(text);
m_speech.say(text);
}

void TextToSpeechBar::stop()
{
mp_speech->stop();
m_speech.stop();
}

void TextToSpeechBar::onStateChanged(QTextToSpeech::State state)
Expand All @@ -63,8 +64,9 @@ void TextToSpeechBar::languageSelected(int index)
disconnect(mp_ui->voiceComboBox, &QComboBox::currentIndexChanged, this, &TextToSpeechBar::voiceSelected);
mp_ui->voiceComboBox->clear();

m_voices = mp_speech->availableVoices();
QVoice currentVoice = mp_speech->voice();
m_speech.setLocale(locale);
m_voices = m_speech.availableVoices();
QVoice currentVoice = m_speech.voice();
for (auto voice : m_voices)
{
mp_ui->voiceComboBox->addItem(QString("%1 - %2 - %3").arg(voice.name())
Expand All @@ -78,7 +80,7 @@ void TextToSpeechBar::languageSelected(int index)

void TextToSpeechBar::voiceSelected(int index)
{
mp_speech->setVoice(m_voices.at(index));
m_speech.setVoice(m_voices.at(index));
}

void TextToSpeechBar::speechBarClose()
Expand All @@ -89,6 +91,6 @@ void TextToSpeechBar::speechBarClose()
return;
current->setFocus();

mp_speech->stop();
m_speech.stop();
close();
}
2 changes: 1 addition & 1 deletion src/texttospeechbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public slots:
void onStateChanged(QTextToSpeech::State state);

private:
QTextToSpeech *mp_speech;
static QTextToSpeech m_speech;
Ui::TextToSpeechBar *mp_ui;
QVector<QVoice> m_voices;
};
Expand Down
2 changes: 1 addition & 1 deletion src/texttospeechbar.ui
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string/>
</property>
<property name="text">
<string/>
Expand Down
4 changes: 2 additions & 2 deletions src/zimview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ ZimView::ZimView(TabBar *tabBar, QWidget *parent)
return;
mp_ttsBar->speak(mp_webView->page()->selectedText());
});
connect(app->getAction(KiwixApp::ReadTextAction), &QAction::triggered, [=](){
connect(app->getAction(KiwixApp::ReadTextAction), &QAction::triggered, this, [=](){
if (mp_tabBar->currentZimView() != this)
return;
if (this->getWebView()->page()->hasSelection())
mp_ttsBar->show();
});
connect(app->getAction(KiwixApp::ReadArticleAction), &QAction::triggered, [=](){
connect(app->getAction(KiwixApp::ReadArticleAction), &QAction::triggered, this, [=](){
if (mp_tabBar->currentZimView() == this)
mp_ttsBar->show();
});
Expand Down

0 comments on commit 6937c65

Please sign in to comment.