- hotkey-support (Ctrl-E) to switch between configured font and a fixed width font,

- fixed a few minor buglets,
- some tuning in in the mail-rendering engine (quotedHTML()),
- removed unneeded mSavedEditorFont variable,
- Thanks to Michael Häckel for reviewing

svn path=/trunk/kdenetwork/kmail/; revision=120657
wilder-work
Helge Deller 25 years ago
parent f04f3f43fe
commit d5fc2361c4
  1. 4
      kmcomposerui.rc
  2. 20
      kmcomposewin.cpp
  3. 11
      kmcomposewin.h
  4. 50
      kmmainwin.cpp
  5. 4
      kmmainwin.h
  6. 11
      kmmessage.cpp
  7. 3
      kmmessage.h
  8. 150
      kmreaderwin.cpp
  9. 8
      kmreaderwin.h

@ -1,4 +1,4 @@
<!DOCTYPE kpartgui ><kpartgui version="6" name="kmcomposer" >
<!DOCTYPE kpartgui ><kpartgui version="7" name="kmcomposer" >
<MenuBar>
<Menu noMerge="1" name="file" >
<text>&amp;Message</text>
@ -45,6 +45,8 @@
<Action name="show_cc" />
<Action name="show_bcc" />
<Action name="show_subject" />
<Separator/>
<Action name="toggle_fixedfont" />
</Menu>
<Menu name="attach" >
<text>&amp;Attach</text>

@ -20,6 +20,7 @@
#include "kmtransport.h"
#include <kaction.h>
#include <kglobalsettings.h>
#include <kcharsets.h>
#include <kcompletionbox.h>
#include <kcursor.h>
@ -62,7 +63,7 @@
#include "kmcomposewin.moc"
//-----------------------------------------------------------------------------
KMComposeWin::KMComposeWin(KMMessage *aMsg, QString id )
KMComposeWin::KMComposeWin(KMMessage *aMsg, QString id)
: KMTopLevelWidget (), MailComposerIface(),
mId( id )
@ -105,6 +106,7 @@ KMComposeWin::KMComposeWin(KMMessage *aMsg, QString id )
mAutoDeleteMsg = FALSE;
mFolder = NULL;
mEditor = new KMEdit(mMainWidget, this);
mEditor->setTextFormat(Qt::PlainText);
disableBreaking = false;
QString tip = i18n("Select email address(es)");
QToolTip::add( mBtnTo, tip );
@ -172,9 +174,6 @@ KMComposeWin::KMComposeWin(KMMessage *aMsg, QString id )
mEditor->setExternalEditorPath(mExtEditor);
}
// As family may change with charset, we must save original settings
mSavedEditorFont=mEditor->font();
mMsg = NULL;
if (aMsg)
setMsg(aMsg);
@ -792,6 +791,9 @@ void KMComposeWin::setupActions(void)
(void) new KAction (i18n("Cl&ean Spaces"), 0, this, SLOT(slotCleanSpace()),
actionCollection(), "clean_spaces");
(void) new KToggleAction( i18n("Fixed font widths"), DEFAULT_FIXEDFONTS_KEY, this,
SLOT(slotToggleFixedFont()), actionCollection(), "toggle_fixedfont" );
//these are checkable!!!
urgentAction = new KToggleAction (i18n("&Urgent"), 0,
actionCollection(),
@ -983,6 +985,8 @@ void KMComposeWin::setupEditor(void)
menu->insertSeparator();
menu->insertItem(i18n("Find..."), this, SLOT(slotFind()));
menu->insertItem(i18n("Replace..."), this, SLOT(slotReplace()));
menu->insertSeparator();
menu->insertItem(i18n("Fixed font widths"), this, SLOT(slotToggleFixedFont()));
mEditor->installRBPopup(menu);
updateCursorPosition();
connect(mEditor,SIGNAL(CursorPositionChanged()),SLOT(updateCursorPosition()));
@ -1960,6 +1964,14 @@ void KMComposeWin::slotReplace()
mEditor->replace();
}
//-----------------------------------------------------------------------------
void KMComposeWin::slotToggleFixedFont()
{
if (!mEditor) return;
QFont fixedfont = KGlobalSettings::fixedFont();
mEditor->setFont( (mEditor->font() == fixedfont) ? mBodyFont : fixedfont );
}
//-----------------------------------------------------------------------------
void KMComposeWin::slotUndo()

@ -55,6 +55,8 @@ class KURL;
typedef QPtrList<KMMessagePart> KMMsgPartList;
/* default key to toggle between fixed width font and default font */
#define DEFAULT_FIXEDFONTS_KEY (CTRL+Key_E)
//-----------------------------------------------------------------------------
#define KMEditInherited KEdit
@ -157,7 +159,7 @@ class KMComposeWin : public KMTopLevelWidget, virtual public MailComposerIface
friend class KMHeaders; // needed for the digest forward
public:
KMComposeWin(KMMessage* msg=0L, QString id = "unknown" );
KMComposeWin(KMMessage* msg=0L, QString id = "unknown");
~KMComposeWin();
/**
@ -261,6 +263,12 @@ public slots:
void slotCopy();
void slotPaste();
void slotMarkAll();
/**
* toggle fixed width font.
*/
void slotToggleFixedFont();
/**
* Open addressbook editor dialog.
*/
@ -528,7 +536,6 @@ protected:
QCString mCharset;
QCString mDefCharset;
QFont mSavedEditorFont;
QStringList mFolderNames;
QValueList<QGuardedPtr<KMFolder> > mFolderList;

@ -1082,10 +1082,17 @@ void KMMainWin::slotShowMsgSrc()
if (!cset.isEmpty())
codec = KMMsgBase::codecForName(cset);
}
msg->viewSource(i18n("Message as Plain Text"), codec);
msg->viewSource(i18n("Message as Plain Text"), codec,
mMsgView->isfixedFont());
}
}
//-----------------------------------------------------------------------------
void KMMainWin::slotToggleFixedFont()
{
mMsgView->slotToggleFixedFont();
}
//-----------------------------------------------------------------------------
void KMMainWin::slotMoveMsg()
@ -1168,17 +1175,20 @@ void KMMainWin::slotViewChange()
//-----------------------------------------------------------------------------
void KMMainWin::slotSetHeaderStyle(int id)
{
if(id <= 5)
if (id >= KMReaderWin::HdrBrief && id <= KMReaderWin::HdrAll)
{
mViewMenu->setItemChecked((int)mMsgView->headerStyle(), FALSE);
mMsgView->setHeaderStyle((KMReaderWin::HeaderStyle)id);
mViewMenu->setItemChecked(id, TRUE);
return;
}
else
if (id >= 5+KMReaderWin::IconicAttmnt && id <= 5+KMReaderWin::InlineAttmnt)
{
mViewMenu->setItemChecked((int)mMsgView->attachmentStyle()+5, FALSE);
mViewMenu->setItemChecked(id, TRUE);
mMsgView->setAttachmentStyle(id-5);
return;
}
}
@ -1474,11 +1484,11 @@ void KMMainWin::slotUrlClicked(const KURL &aUrl, int)
// It is correct to convert to latin1() as URL should not contain
// anything except ascii.
msg->setBody( KURL::decode_string(queryPart.mid(6)).latin1() );
else if (queryPart.left(6) == "?cc=")
else if (queryPart.left(4) == "?cc=")
msg->setCc( KURL::decode_string(queryPart.mid(4)) );
}
win = new KMComposeWin(msg,id);
win = new KMComposeWin(msg, id);
win->setCharset("", TRUE);
win->show();
}
@ -1516,7 +1526,7 @@ void KMMainWin::slotMailtoCompose()
msg->setCharset("utf-8");
msg->setTo(mUrlCurrent.path());
win = new KMComposeWin(msg,id);
win = new KMComposeWin(msg, id);
win->setCharset("", TRUE);
win->show();
}
@ -1536,7 +1546,7 @@ void KMMainWin::slotMailtoReply()
rmsg = msg->createReply(FALSE, FALSE, mMsgView->copyText());
rmsg->setTo(mUrlCurrent.path());
win = new KMComposeWin(rmsg,id);
win = new KMComposeWin(rmsg, id);
win->setCharset(msg->codec()->name(), TRUE);
win->setReplyFocus();
win->show();
@ -1660,6 +1670,10 @@ void KMMainWin::slotMsgPopup(const KURL &aUrl, const QPoint& aPoint)
moveActionMenu->plug( menu );
copyActionMenu->plug( menu );
menu->insertSeparator();
toggleFixFontAction->plug(menu);
viewSourceAction->plug(menu);
menu->insertSeparator();
printAction->plug(menu);
saveAsAction->plug(menu);
@ -1688,7 +1702,8 @@ void KMMainWin::getAccountMenu()
void KMMainWin::setupMenuBar()
{
//----- File Menu
(void) new KAction( i18n("&New Mail Client..."), "window_new", 0, this, SLOT(slotNewMailReader()),
(void) new KAction( i18n("&New Mail Client..."), "window_new", 0,
this, SLOT(slotNewMailReader()),
actionCollection(), "new_mail_client" );
saveAsAction = new KAction( i18n("Save &As..."), "filesave",
@ -1822,7 +1837,8 @@ void KMMainWin::setupMenuBar()
SLOT(slotResendMsg()), actionCollection(), "send_again" );
//----- Message-Encoding Submenu
mEncoding = new KSelectAction( i18n( "Set &Encoding" ), "charset", 0, this, SLOT( slotSetEncoding() ), actionCollection(), "encoding" );
mEncoding = new KSelectAction( i18n( "Set &Encoding" ), "charset", 0, this,
SLOT( slotSetEncoding() ), actionCollection(), "encoding" );
QStringList encodings = KMMsgBase::supportedEncodings(FALSE);
encodings.prepend( i18n( "Auto" ) );
mEncoding->setItems( encodings );
@ -1912,13 +1928,14 @@ void KMMainWin::setupMenuBar()
(void) new KAction( i18n("Apply filters"), "filter", CTRL+Key_J, this,
SLOT(slotApplyFilters()), actionCollection(), "apply_filters" );
(void) new KAction( i18n("View Source..."), 0, this,
viewSourceAction = new KAction( i18n("View Source..."), Key_V, this,
SLOT(slotShowMsgSrc()), actionCollection(), "view_source" );
//----- View Menu
KActionMenu *viewMenuAction = new
KActionMenu( i18n("things to show", "&View"), actionCollection(), "view" );
KActionMenu( i18n("&View"), actionCollection(), "view" );
mViewMenu = viewMenuAction->popupMenu();
mViewMenu->setCheckable(TRUE);
@ -1937,6 +1954,13 @@ void KMMainWin::setupMenuBar()
KMReaderWin::HdrAll + KMReaderWin::InlineAttmnt);
mViewMenu->setItemChecked((int)mMsgView->headerStyle(), TRUE);
mViewMenu->setItemChecked((int)mMsgView->attachmentStyle()+5, TRUE);
mViewMenu->insertSeparator();
toggleFixFontAction = new KToggleAction( i18n("Fixed font widths"),
DEFAULT_FIXEDFONTS_KEY, this, SLOT(slotToggleFixedFont()),
actionCollection(), "toggle_fixedfont" );
viewMenuAction->insert( toggleFixFontAction );
//----- Settings Menu
toolbarAction = KStdAction::showToolbar(this, SLOT(slotToggleToolBar()),
@ -2184,7 +2208,7 @@ void KMMainWin::updateMessageActions()
sendAgainAction->setEnabled( single_actions );
printAction->setEnabled( single_actions );
saveAsAction->setEnabled( mass_actions );
action( "view_source" )->setEnabled( single_actions );
viewSourceAction->setEnabled( single_actions );
if ( count == 1 ) {
KMMessage *msg;

@ -79,7 +79,8 @@ public:
KAction *replyAction, *noQuoteReplyAction, *replyAllAction, *replyListAction,
*forwardAction, *forwardAttachedAction, *redirectAction,
*deleteAction, *saveAsAction, *bounceAction, *editAction,
*printAction, *sendAgainAction;
*viewSourceAction, *printAction, *sendAgainAction;
KToggleAction *toggleFixFontAction;
KActionMenu *filterMenu, *statusMenu, *moveActionMenu, *copyActionMenu;
void folderSelected(KMFolder*, bool jumpToUnread);
@ -174,6 +175,7 @@ protected slots:
void slotSetMsgStatusSent();
void slotSetMsgStatusFlag();
void slotShowMsgSrc();
void slotToggleFixedFont();
void slotSetHeaderStyle(int);
void slotSetEncoding();
void slotSendQueued();

@ -16,6 +16,7 @@
#include "kmidentity.h"
#include <kapplication.h>
#include <kglobalsettings.h>
#include <khtml_part.h>
// we need access to the protected member DwBody::DeleteBodyParts()...
@ -2075,19 +2076,23 @@ void KMMessage::addBodyPart(const KMMessagePart* aPart)
//-----------------------------------------------------------------------------
void KMMessage::viewSource(const QString& aCaption, QTextCodec *codec)
void KMMessage::viewSource(const QString& aCaption, QTextCodec *codec, bool fixedfont)
{
QString str = (codec) ? codec->toUnicode(asString()) : asString();
#if ALLOW_GUI
QMultiLineEdit* edt;
QMultiLineEdit *edt;
edt = new QMultiLineEdit;
KWin::setIcons(edt->winId(), kapp->icon(), kapp->miniIcon());
if (!aCaption.isEmpty()) edt->setCaption(aCaption);
edt->insertLine(str);
edt->setTextFormat(Qt::PlainText);
edt->setText(str);
if (fixedfont)
edt->setFont(KGlobalSettings::fixedFont());
edt->setReadOnly(TRUE);
edt->resize(KApplication::desktop()->width()/2,
2*KApplication::desktop()->height()/3);
edt->setCursorPosition(0, 0); edt->show();

@ -281,7 +281,8 @@ public:
virtual void deleteBodyParts(void);
/** Open a window containing the complete, unparsed, message. */
virtual void viewSource(const QString& windowCaption, QTextCodec *codec);
virtual void viewSource(const QString& windowCaption, QTextCodec *codec,
bool fixedfont);
/** Set "Status" and "X-Status" fields of the message from the
* internal message status. */

@ -78,6 +78,7 @@ KMReaderWin::KMReaderWin(QWidget *aParent, const char *aName, int aFlags)
initHtmlWidget();
readConfig();
mHtmlOverride = false;
mUseFixedFont = false;
connect( &updateReaderWinTimer, SIGNAL(timeout()),
this, SLOT(updateReaderWin()) );
@ -278,7 +279,7 @@ QString KMReaderWin::quoteFontTag( int quoteLevel )
}
}
QString str = QString("<font color=\"%1\">").arg( color.name() );
QString str = QString("<span style=\"color:%1\">").arg( color.name() );
if( font.italic() ) { str += "<i>"; }
if( font.bold() ) { str += "<b>"; }
return( str );
@ -430,6 +431,7 @@ void KMReaderWin::displayAboutPage()
"<li>DIGEST-MD5 authentication</li>\n"
"<li>Identity based sent-mail folders</li>\n"
"<li>Expiry of old messages</li>\n"
"<li>Hotkey to temporary switch to fixed width fonts</li>\n"
"</ul>\n");
if( kernel->firstStart() ) {
info += i18n("<p>Please take a moment to fill in the KMail configuration panel at "
@ -896,94 +898,90 @@ void KMReaderWin::writeBodyStr(const QCString aStr, QTextCodec *aCodec)
QString KMReaderWin::quotedHTML(const QString& s)
{
QString htmlStr, line, tmpStr, normalStartTag, normalEndTag;
QChar ch;
QString htmlStr, line, normalStartTag, normalEndTag;
QString quoteEnd("</span>");
bool atStartOfLine;
int pos, beg;
unsigned int pos, beg;
unsigned int length = s.length();
int currQuoteLevel = -1;
int prevQuoteLevel = -1;
int newlineCount = 0;
if (mBodyFont.bold()) { normalStartTag += "<b>"; normalEndTag += "</b>"; }
if (mBodyFont.italic()) { normalStartTag += "<i>"; normalEndTag += "</i>"; }
tmpStr = "<div>" + normalStartTag; //work around KHTML slowness
// skip leading empty lines
for( pos = 0; pos < (int)s.length() && s[pos] <= ' '; pos++ );
for( pos = 0; pos < length && s[pos] <= ' '; pos++ );
while (pos > 0 && (s[pos-1] == ' ' || s[pos-1] == '\t')) pos--;
beg = pos;
atStartOfLine = TRUE;
while( pos < (int)s.length() )
htmlStr = normalStartTag;
if (mUseFixedFont)
htmlStr.append("<pre>");
int currQuoteLevel = -1;
while (beg<length)
{
ch = s[pos];
if(( ch == '\n' ) || ((unsigned)pos == s.length() - 1))
{
int adj = (ch == '\n') ? 0 : 1;
newlineCount ++;
line = strToHtml(s.mid(beg,pos-beg+adj),TRUE);
if( currQuoteLevel >= 0 )
{
if( currQuoteLevel != prevQuoteLevel )
{
line.prepend( mQuoteFontTag[currQuoteLevel%3] );
if( prevQuoteLevel >= 0 )
{
line.prepend( "</font>" );
} else line.prepend( normalEndTag );
/* search next occurance of '\n' */
pos = s.find('\n', beg, FALSE);
if (pos == (unsigned int)(-1))
pos = length;
line = s.mid(beg,pos-beg);
beg = pos+1;
/* calculate line's current quoting depth */
int p, actQuoteLevel = -1;
bool finish = FALSE;
for (p=0; p<line.length() && !finish; p++) {
switch (line[p].latin1()) {
/* case ':': */
case '>':
case '|': actQuoteLevel++;
break;
case ' ':
case '\t': break;
default: finish = TRUE;
break;
}
prevQuoteLevel = currQuoteLevel;
}
else if( prevQuoteLevel >= 0 )
{
line.prepend( normalStartTag );
line.prepend( "</font>" );
prevQuoteLevel = -1;
}
tmpStr += line + "<br>";
if( (newlineCount % 100) == 0 )
{
htmlStr += tmpStr;
if (currQuoteLevel >= 0)
htmlStr += "</font>";
else htmlStr += normalEndTag;
htmlStr += "</div><div>"; //work around KHTML slowness
if (currQuoteLevel >= 0)
htmlStr += mQuoteFontTag[currQuoteLevel%3];
else htmlStr += normalStartTag;
tmpStr.truncate(0);
}
} /* for() */
beg = pos + 1;
atStartOfLine = TRUE;
currQuoteLevel = -1;
line = strToHtml(line, TRUE);
p = line.length();
line.append("<br>\n");
}
else if( ch > ' ' )
{
if( atStartOfLine == TRUE && (ch=='>' || /*ch==':' ||*/ ch=='|') )
{
if( mRecyleQouteColors == true || currQuoteLevel < 2 )
{
currQuoteLevel += 1;
}
}
else
{
atStartOfLine = FALSE;
}
/* continue with current quotelevel if it didn't changed */
if (actQuoteLevel == currQuoteLevel || p == 0) {
htmlStr.append(line);
continue;
}
pos++;
}
/* finish last quotelevel */
if (mUseFixedFont)
htmlStr.append("</pre>");
if (currQuoteLevel == -1)
htmlStr.append( normalEndTag );
else
htmlStr.append( quoteEnd );
if (prevQuoteLevel >= 0)
tmpStr += "</font>";
/* start new quotelevel */
currQuoteLevel = actQuoteLevel;
if (actQuoteLevel == -1)
line.prepend(normalStartTag);
else
line.prepend( mQuoteFontTag[currQuoteLevel%3] );
if (mUseFixedFont)
line.prepend("<pre>");
htmlStr.append(line);
} /* while() */
/* really finish the last quotelevel */
if (mUseFixedFont)
htmlStr.append("</pre>");
if (currQuoteLevel == -1)
htmlStr.append( normalEndTag );
else
htmlStr.append( quoteEnd );
htmlStr += tmpStr;
htmlStr += "</div>"; //work around KHTML slowness
return htmlStr;
}
@ -1335,6 +1333,14 @@ void KMReaderWin::slotFind()
act->activate();
}
//-----------------------------------------------------------------------------
void KMReaderWin::slotToggleFixedFont()
{
mUseFixedFont = !mUseFixedFont;
update(true);
}
//-----------------------------------------------------------------------------
void KMReaderWin::atmViewMsg(KMMessagePart* aMsgPart)
{

@ -50,7 +50,7 @@ public:
virtual void setInlineAttach(int maxLines);
/** Style of the message header. */
enum HeaderStyle { HdrFancy=1, HdrBrief=2, HdrStandard=3, HdrLong=4,
enum HeaderStyle { HdrBrief=1, HdrFancy=2, HdrStandard=3, HdrLong=4,
HdrAll=5 };
/** Style of attachments. */
enum AttachmentStyle {IconicAttmnt=1, SmartAttmnt =2, InlineAttmnt = 3};
@ -118,6 +118,8 @@ public:
bool atBottom() const;
bool isfixedFont() { return mUseFixedFont; }
signals:
/** Emitted to show a text on the status line. */
void statusMsg(const QString& text);
@ -164,6 +166,9 @@ public slots:
/** The user selected "Find" from the menu. */
void slotFind();
/** The user toggled the "Fixed Font" flag from the view menu. */
void slotToggleFixedFont();
protected slots:
/** Some attachment operations. */
void slotAtmOpen();
@ -250,6 +255,7 @@ protected:
bool mMsgDisplay;
int fntSize;
bool mUseFixedFont;
QString mBodyFamily;
QColor c1, c2, c3, c4;
QString mQuoteFontTag[3];

Loading…
Cancel
Save