Commit 8a7ed6cd authored by Laurent Montel's avatar Laurent Montel 😁

Add a special dictionnary combobox

parent 90c2fbf1
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.7.42")
set(PIM_VERSION "5.7.43")
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
......
......@@ -113,8 +113,12 @@ set(messagecomposer_plugineditorinit_SRCS
plugineditorinit/plugineditorinitinterface.cpp
)
set(messagecomposer_widgets_SRCS
widgets/dictionarycombobox.cpp
)
set( messagecomposer_src
${messagecomposer_widgets_SRCS}
${messagecomposer_plugineditorinit_SRCS}
${messagecomposer_plugineditor_SRCS}
${messagecomposer_richtextcomposerng_SRCS}
......@@ -184,6 +188,7 @@ target_link_libraries(KF5MessageComposer
KF5::FollowupReminder
KF5::Archive
KF5::Contacts
KF5::SonnetCore
)
target_include_directories(KF5MessageComposer INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/MessageComposer/;${KDE_INSTALL_INCLUDEDIR_KF5}/messagecomposer>")
......@@ -221,6 +226,15 @@ ecm_generate_headers(MessageComposer_Camelplugineditorinit_HEADERS
RELATIVE plugineditorinit
)
ecm_generate_headers(MessageComposer_Camelwidgets_HEADERS
HEADER_NAMES
DictionaryComboBox
REQUIRED_HEADERS MessageComposer_widgets_HEADERS
PREFIX MessageComposer
RELATIVE widgets
)
ecm_generate_headers(MessageComposer_Camelplugineditorcheckbeforesend_HEADERS
HEADER_NAMES
PluginEditorCheckBeforeSend
......@@ -381,6 +395,7 @@ install(FILES
${MessageComposer_Camelcasejob_HEADERS}
${MessageComposer_Camelcaseattachement_HEADERS}
${MessageComposer_Camelplugineditor_HEADERS}
${MessageComposer_Camelwidgets_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageComposer
COMPONENT Devel
)
......@@ -391,6 +406,7 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/messagecomposer_export.h
${CMAKE_CURRENT_BINARY_DIR}/messagecomposersettings_base.h
${CMAKE_CURRENT_BINARY_DIR}/messagecomposer_debug.h
${MessageComposer_widgets_HEADERS}
${MessageComposer_composer_HEADERS}
${MessageComposer_composerng_HEADERS}
${MessageComposer_sender_HEADERS}
......
/*
* Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
* Copyright (c) 2008 Tom Albers <tomalbers@kde.nl>
* Copyright (c) 2017 Laurent Montel <montel@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "dictionarycombobox.h"
#include <SonnetCore/sonnet/speller.h>
#include "messagecomposer_debug.h"
namespace MessageComposer
{
//@cond PRIVATE
class DictionaryComboBoxPrivate
{
public:
explicit DictionaryComboBoxPrivate(DictionaryComboBox *combo) : q(combo) {}
DictionaryComboBox *q;
void slotDictionaryChanged(int idx);
};
void DictionaryComboBoxPrivate::slotDictionaryChanged(int idx)
{
Q_EMIT q->dictionaryChanged(q->itemData(idx).toString());
Q_EMIT q->dictionaryNameChanged(q->itemText(idx));
}
//@endcon
DictionaryComboBox::DictionaryComboBox(QWidget *parent)
: QComboBox(parent), d(new DictionaryComboBoxPrivate(this))
{
reloadCombo();
connect(this, SIGNAL(activated(int)),
SLOT(slotDictionaryChanged(int)));
}
DictionaryComboBox::~DictionaryComboBox()
{
delete d;
}
QString DictionaryComboBox::currentDictionaryName() const
{
return currentText();
}
QString DictionaryComboBox::currentDictionary() const
{
return itemData(currentIndex()).toString();
}
bool DictionaryComboBox::assignDictionnaryName(const QString &name)
{
if (name.isEmpty() || name == currentText()) {
return false;
}
int idx = findText(name);
if (idx == -1) {
qCDebug(MESSAGECOMPOSER_LOG) << "name not found" << name;
return false;
}
setCurrentIndex(idx);
d->slotDictionaryChanged(idx);
return true;
}
void DictionaryComboBox::setCurrentByDictionaryName(const QString &name)
{
assignDictionnaryName(name);
}
bool DictionaryComboBox::assignByDictionnary(const QString &dictionary)
{
if (dictionary.isEmpty()) {
return false;
}
if (dictionary == itemData(currentIndex()).toString()) {
return true;
}
int idx = findData(dictionary);
if (idx == -1) {
qCDebug(MESSAGECOMPOSER_LOG) << "dictionary not found" << dictionary;
return false;
}
setCurrentIndex(idx);
d->slotDictionaryChanged(idx);
return true;
}
void DictionaryComboBox::setCurrentByDictionary(const QString &dictionary)
{
assignByDictionnary(dictionary);
}
void DictionaryComboBox::reloadCombo()
{
clear();
Sonnet::Speller *speller = new Sonnet::Speller();
QMap<QString, QString> dictionaries = speller->availableDictionaries();
QMapIterator<QString, QString> i(dictionaries);
while (i.hasNext()) {
i.next();
addItem(i.key(), i.value());
}
delete speller;
}
}
#include "moc_dictionarycombobox.cpp"
/*
* Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
* Copyright (c) 2008 Tom Albers <tomalbers@kde.nl>
* Copyright (c) 2017 Laurent Montel <montel@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef SONNET_DICTIONARYCOMBOBOX_H
#define SONNET_DICTIONARYCOMBOBOX_H
#include "messagecomposer_export.h"
#include <QComboBox>
namespace MessageComposer
{
class DictionaryComboBoxPrivate;
/**
* @short A combo box for selecting the dictionary used for spell checking.
* @author Ingo Kloecker <kloecker@kde.org>
* @author Tom Albers <tomalbers@kde.nl>
* @since 4.2
**/
class MESSAGECOMPOSER_EXPORT DictionaryComboBox : public QComboBox
{
Q_OBJECT
public:
/**
* Constructor
*/
explicit DictionaryComboBox(QWidget *parent = nullptr);
/**
* Destructor
*/
~DictionaryComboBox();
/**
* Clears the widget and reloads the dictionaries from Sonnet.
* Remember to set the dictionary you want selected after calling this function.
*/
void reloadCombo();
/**
* Returns the current dictionary name, for example "German (Switzerland)"
*/
QString currentDictionaryName() const;
/**
* Returns the current dictionary, for example "de_CH"
*/
QString currentDictionary() const;
/**
* Sets the current dictionaryName to the given dictionaryName
*/
void setCurrentByDictionaryName(const QString &dictionaryName);
/**
* Sets the current dictionary to the given dictionary
* Return true if dictionnary was found.
* @since 5.40
* TODO merge with previous method in kf6
*/
bool assignByDictionnary(const QString &dictionary);
/**
* Sets the current dictionaryName to the given dictionaryName
* Return true if dictionnary was found.
* @since 5.40
* TODO merge with previous method in kf6
*/
bool assignDictionnaryName(const QString &name);
/**
* Sets the current dictionary to the given dictionary.
*/
void setCurrentByDictionary(const QString &dictionary);
Q_SIGNALS:
/**
* @em Emitted whenever the current dictionary changes. Either
* by user intervention or on setCurrentByDictionaryName() or on
* setCurrentByDictionary(). For example "de_CH".
*/
void dictionaryChanged(const QString &dictionary);
/**
* @em Emitted whenever the current dictionary changes. Either
* by user intervention or on setCurrentByDictionaryName() or on
* setCurrentByDictionary(). For example "German (Switzerland)".
*/
void dictionaryNameChanged(const QString &dictionaryName);
private:
DictionaryComboBoxPrivate *const d;
Q_PRIVATE_SLOT(d, void slotDictionaryChanged(int))
};
}
#endif
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