Commit 11443941 authored by Laurent Montel's avatar Laurent Montel 😁

Add new widget to change override mode now we can click on this widget which is

in statusbar to change mode
parent 5d32e36f
......@@ -161,6 +161,7 @@ if (KDEPIM_BUILD_DESKTOP)
widgets/collectionpane.cpp
widgets/vacationscriptindicatorwidget.cpp
widgets/displaymessageformatactionmenu.cpp
widgets/overwritemodewidget.cpp
)
set(kmailprivate_tag_LIB_SRCS
tag/tagactionmanager.cpp
......
......@@ -110,6 +110,8 @@
#include "mailcommon/folder/folderrequester.h"
#include "mailcommon/folder/foldercollection.h"
#include "widgets/overwritemodewidget.h"
// LIBKDEPIM includes
#include <libkdepim/addressline/recentaddresses.h>
......@@ -229,7 +231,9 @@ KMComposeWin::KMComposeWin( const KMime::Message::Ptr &aMsg, bool lastSignState,
mWasModified( false ),
mCryptoStateIndicatorWidget(0),
mStorageService(new KMStorageService(this, this)),
mSendNowByShortcutUsed(false)
mSendNowByShortcutUsed(false),
mFollowUpToggleAction(0),
mOverwriteModeWidget(0)
{
m_verifyMissingAttachment = 0;
mComposerBase = new MessageComposer::ComposerViewBase( this, this );
......@@ -1435,10 +1439,10 @@ void KMComposeWin::setupActions( void )
mComposerBase->editor()->createActions( actionCollection() );
actionCollection()->addAction( QLatin1String("shared_link"), mStorageService->menuShareLinkServices() );
KToggleAction *followUpToggelAction = new KToggleAction( i18n("Follow Up Mail..."), this );
actionCollection()->addAction( QLatin1String("follow_up_mail"), followUpToggelAction );
connect( followUpToggelAction, SIGNAL(triggered(bool)), this, SLOT(slotFollowUpMail(bool)) );
followUpToggelAction->setEnabled(FollowUpReminder::FollowUpReminderUtil::followupReminderAgentEnabled());
mFollowUpToggleAction = new KToggleAction( i18n("Follow Up Mail..."), this );
actionCollection()->addAction( QLatin1String("follow_up_mail"), mFollowUpToggleAction );
connect( mFollowUpToggleAction, SIGNAL(triggered(bool)), this, SLOT(slotFollowUpMail(bool)) );
mFollowUpToggleAction->setEnabled(FollowUpReminder::FollowUpReminderUtil::followupReminderAgentEnabled());
createGUI( QLatin1String("kmcomposerui.rc") );
connect( toolBar( QLatin1String("htmlToolBar") )->toggleViewAction(),
......@@ -1486,7 +1490,9 @@ void KMComposeWin::setupStatusBar( QWidget *w )
statusBar()->insertItem( QString(), 0, 1 );
statusBar()->setItemAlignment( 0, Qt::AlignLeft | Qt::AlignVCenter );
statusBar()->insertPermanentItem( overwriteModeStr(), 4,0 );
mOverwriteModeWidget = new OverwriteModeWidget(this);
statusBar()->addPermanentWidget(mOverwriteModeWidget,0 );
connect(mOverwriteModeWidget, SIGNAL(overwriteModeChanged(bool)), this, SLOT(slotOverwriteModeWasChanged(bool)));
statusBar()->insertPermanentItem( i18n(" Spellcheck: %1 ", QLatin1String( " " )), 3, 0) ;
statusBar()->insertPermanentItem( i18n(" Column: %1 ", QLatin1String( " " ) ), 2, 0 );
......@@ -3338,13 +3344,9 @@ void KMComposeWin::slotFolderRemoved( const Akonadi::Collection & col )
void KMComposeWin::slotOverwriteModeChanged()
{
mComposerBase->editor()->setCursorWidth( mComposerBase->editor()->overwriteMode () ? 5 : 1 );
statusBar()->changeItem( overwriteModeStr(), 4 );
}
QString KMComposeWin::overwriteModeStr() const
{
return mComposerBase->editor()->overwriteMode () ? i18n("OVR") : i18n ("INS");
const bool overwriteMode = mComposerBase->editor()->overwriteMode ();
mComposerBase->editor()->setCursorWidth( overwriteMode ? 5 : 1 );
mOverwriteModeWidget->setOverwriteMode(overwriteMode);
}
void KMComposeWin::slotCursorPositionChanged()
......@@ -3625,6 +3627,8 @@ void KMComposeWin::slotFollowUpMail(bool toggled)
if (dlg->exec()) {
mFollowUpDate = dlg->selectedDate();
mFollowUpCollection = dlg->collection();
} else {
mFollowUpToggleAction->setChecked(false);
}
delete dlg;
} else {
......@@ -3638,3 +3642,9 @@ void KMComposeWin::slotSnippetWidgetVisibilityChanged(bool b)
mSnippetWidget->setVisible(b);
mSnippetSplitterCollapser->setVisible(b);
}
void KMComposeWin::slotOverwriteModeWasChanged(bool state)
{
mComposerBase->editor()->setCursorWidth( state ? 5 : 1 );
mComposerBase->editor()->setOverwriteMode (state);
}
......@@ -69,7 +69,7 @@ class AttachmentMissingWarning;
class ExternalEditorWarning;
class KActionMenu;
class CryptoStateIndicatorWidget;
class OverwriteModeWidget;
namespace boost {
template <typename T> class shared_ptr;
......@@ -458,6 +458,7 @@ private slots:
void slotFollowUpMail(bool toggled);
void slotSendNowByShortcut();
void slotSnippetWidgetVisibilityChanged(bool b);
void slotOverwriteModeWasChanged(bool state);
public: // kmcommand
// FIXME we need to remove these, but they're pure virtual in Composer.
void addAttach( KMime::Content *msgPart );
......@@ -484,7 +485,6 @@ private:
void updateSignature(uint uoid, uint uOldId);
Kleo::CryptoMessageFormat cryptoMessageFormat() const;
QString overwriteModeStr() const;
void printComposeResult( KJob *job, bool preview );
void printComposer(bool preview);
/**
......@@ -696,6 +696,8 @@ private:
KMStorageService *mStorageService;
bool mSendNowByShortcutUsed;
PimCommon::SplitterCollapser *mSnippetSplitterCollapser;
KToggleAction *mFollowUpToggleAction;
OverwriteModeWidget *mOverwriteModeWidget;
};
#endif
......@@ -28,3 +28,7 @@ kde4_add_unit_test( followupreminderselectdatedialogtest ${kmail_followupreminde
target_link_libraries( followupreminderselectdatedialogtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_AKONADI_CALENDAR_LIBS} ${KDEPIMLIBS_KCALCORE_LIBS})
set( kmail_overwritewidget_source overwritemodewidgettest.cpp ../widgets/overwritemodewidget.cpp )
kde4_add_unit_test( overwritemodewidgettest ${kmail_overwritewidget_source})
target_link_libraries( overwritemodewidgettest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS})
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "overwritemodewidgettest.h"
#include "../widgets/overwritemodewidget.h"
#include <qtest_kde.h>
#include <qtestmouse.h>
#include <QSignalSpy>
OverwriteModeWidgetTest::OverwriteModeWidgetTest(QObject *parent)
: QObject(parent)
{
}
OverwriteModeWidgetTest::~OverwriteModeWidgetTest()
{
}
void OverwriteModeWidgetTest::shouldHasDefaultValue()
{
OverwriteModeWidget widget;
QVERIFY(!widget.overwriteMode());
}
void OverwriteModeWidgetTest::shouldChangeState()
{
OverwriteModeWidget widget;
widget.setOverwriteMode(true);
QVERIFY(widget.overwriteMode());
widget.setOverwriteMode(true);
QVERIFY(widget.overwriteMode());
widget.setOverwriteMode(false);
QVERIFY(!widget.overwriteMode());
}
void OverwriteModeWidgetTest::shouldEmitSignalWhenChangeState()
{
OverwriteModeWidget widget;
QSignalSpy spy(&widget, SIGNAL(overwriteModeChanged(bool)));
widget.setOverwriteMode(true);
QCOMPARE(spy.count(), 1);
widget.setOverwriteMode(false);
QCOMPARE(spy.count(), 2);
}
void OverwriteModeWidgetTest::shouldNotEmitSignalWhenWeDontChangeState()
{
OverwriteModeWidget widget;
QSignalSpy spy(&widget, SIGNAL(overwriteModeChanged(bool)));
widget.setOverwriteMode(false);
QCOMPARE(spy.count(), 0);
widget.setOverwriteMode(true);
QCOMPARE(spy.count(), 1);
widget.setOverwriteMode(true);
QCOMPARE(spy.count(), 1);
}
void OverwriteModeWidgetTest::shouldEmitSignalWhenClickOnLabel()
{
OverwriteModeWidget widget;
QSignalSpy spy(&widget, SIGNAL(overwriteModeChanged(bool)));
widget.show();
QTest::qWaitForWindowShown(&widget);
QTest::mouseClick(&widget, Qt::LeftButton);
QCOMPARE(spy.count(), 1);
QTest::mouseClick(&widget, Qt::LeftButton);
QCOMPARE(spy.count(), 2);
}
QTEST_KDEMAIN(OverwriteModeWidgetTest, GUI)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OVERWRITEMODEWIDGETTEST_H
#define OVERWRITEMODEWIDGETTEST_H
#include <QObject>
class OverwriteModeWidgetTest : public QObject
{
Q_OBJECT
public:
explicit OverwriteModeWidgetTest(QObject *parent = 0);
~OverwriteModeWidgetTest();
private Q_SLOTS:
void shouldHasDefaultValue();
void shouldChangeState();
void shouldEmitSignalWhenChangeState();
void shouldNotEmitSignalWhenWeDontChangeState();
void shouldEmitSignalWhenClickOnLabel();
};
#endif // OVERWRITEMODEWIDGETTEST_H
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "overwritemodewidget.h"
#include <KLocalizedString>
#include <QDebug>
OverwriteModeWidget::OverwriteModeWidget(QWidget *parent)
: QLabel(parent),
mOverwriteMode(false)
{
updateLabel();
}
OverwriteModeWidget::~OverwriteModeWidget()
{
}
void OverwriteModeWidget::setOverwriteMode(bool state)
{
if (mOverwriteMode != state) {
mOverwriteMode = state;
Q_EMIT overwriteModeChanged(mOverwriteMode);
updateLabel();
}
}
bool OverwriteModeWidget::overwriteMode() const
{
return mOverwriteMode;
}
void OverwriteModeWidget::updateLabel()
{
if (mOverwriteMode) {
setText(i18n("OVR"));
} else {
setText(i18n("INS"));
}
}
void OverwriteModeWidget::mousePressEvent(QMouseEvent *ev)
{
Q_UNUSED(ev);
setOverwriteMode(!mOverwriteMode);
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef OVERWRITEMODEWIDGET_H
#define OVERWRITEMODEWIDGET_H
#include <QLabel>
class OverwriteModeWidget : public QLabel
{
Q_OBJECT
public:
explicit OverwriteModeWidget(QWidget *parent = 0);
~OverwriteModeWidget();
void setOverwriteMode(bool state);
bool overwriteMode() const;
Q_SIGNALS:
void overwriteModeChanged(bool state);
protected:
void mousePressEvent(QMouseEvent *ev);
private:
void updateLabel();
bool mOverwriteMode;
};
#endif // OVERWRITEMODEWIDGET_H
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