• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kcharselect

kcharselectdia.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999  Reginald Stadlbauer <reggie@kde.org>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of 
00007  * the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include "kcharselectdia.h"
00019 
00020 #include <KAction>
00021 #include <KActionCollection>
00022 #include <KApplication>
00023 #include <KConfig>
00024 #include <KDebug>
00025 #include <KDialog>
00026 #include <KGlobal>
00027 #include <KIcon>
00028 #include <KLocale>
00029 #include <KStandardAction>
00030 #include <KStandardShortcut>
00031 #include <KToggleAction>
00032 
00033 /******************************************************************/
00034 /* class KCharSelectDia                                           */
00035 /******************************************************************/
00036 
00037 //==================================================================
00038 KCharSelectDia::KCharSelectDia()
00039     : KXmlGuiWindow()
00040 {
00041   KSharedConfig::Ptr config = KGlobal::config();
00042   KConfigGroup gr = config->group("General");
00043 
00044   vFont = gr.readEntry("selectedFont", KGlobalSettings::generalFont());
00045   vChr = QChar(static_cast<unsigned short>(gr.readEntry("char", 33)));
00046   _rtl = gr.readEntry("rtl", false);
00047   
00048   QWidget *mainWidget = new QWidget(this);
00049   setCentralWidget(mainWidget);
00050 
00051   grid = new QGridLayout( mainWidget );
00052   grid->setMargin( KDialog::marginHint() );
00053   grid->setSpacing( KDialog::spacingHint() );
00054 
00055   // Add character selection widget from library kdeui
00056   charSelect = new KCharSelect(mainWidget, actionCollection());
00057   charSelect->setCurrentChar(vChr);
00058   charSelect->setCurrentFont(vFont);
00059   charSelect->resize(charSelect->sizeHint());
00060   connect(charSelect,SIGNAL(currentCharChanged(const QChar &)),
00061       SLOT(charChanged(const QChar &)));
00062   connect(charSelect,SIGNAL(charSelected(const QChar &)),
00063       SLOT(add(const QChar &)));
00064   connect(charSelect,SIGNAL(currentFontChanged(const QFont &)),
00065       SLOT(fontSelected(const QFont &)));
00066   grid->addWidget(charSelect, 0, 0, 1, 4);
00067 
00068   // Build line editor
00069   lined = new KLineEdit(mainWidget);
00070   lined->resize(lined->sizeHint());
00071   lined->setClearButtonShown(true);
00072 
00073   lined->setFont( vFont );
00074 
00075   connect(lined,SIGNAL(textChanged(const QString &)),
00076       SLOT(lineEditChanged()));
00077   grid->addWidget(lined, 1, 0, 1, 3);
00078 
00079   bClip = new KPushButton( KGuiItem( i18n( "&To Clipboard" ),
00080             "edit-copy" ), mainWidget );
00081   bClip->setFixedSize( bClip->sizeHint() );
00082   connect(bClip,SIGNAL(clicked()),this,SLOT(toClip()));
00083   grid->addWidget(bClip, 1, 3);
00084 
00085   // Build menu
00086   KStandardAction::quit( this, SLOT(close()), actionCollection() );
00087 
00088   QAction *action = actionCollection()->addAction( "copy_clip" );
00089   action->setText( i18n("&To Clipboard") );
00090   action->setIcon( KIcon("edit-copy") );
00091   connect(action, SIGNAL(triggered(bool)), SLOT(toClip()));
00092   action->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Copy));
00093 
00094   action = actionCollection()->addAction( "copy_utf_8" );
00095   action->setText( i18n("To Clipboard &UTF-8") );
00096   connect(action, SIGNAL(triggered(bool) ), SLOT(toClipUTF8()));
00097   action = actionCollection()->addAction( "copy_html" );
00098   action->setText( i18n("To Clipboard &HTML") );
00099   connect(action, SIGNAL(triggered(bool) ), SLOT(toClipHTML()));
00100 
00101   action = actionCollection()->addAction( "from_clip" );
00102   action->setText( i18n("&From Clipboard") );
00103   action->setIcon( KIcon("edit-paste") );
00104   connect(action, SIGNAL(triggered(bool)), SLOT(fromClip()));
00105   action->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Paste));
00106   action = actionCollection()->addAction( "from_clip_utf8" );
00107   action->setText( i18n( "From Clipboard UTF-8") );
00108   connect(action, SIGNAL(triggered(bool) ), SLOT(fromClipUTF8()));
00109 
00110   i18n("From Clipboard HTML");      // Intended for future use
00111 
00112   action = actionCollection()->addAction( "flip" );
00113   action->setText( i18n("&Flip Text") );
00114   connect(action, SIGNAL(triggered(bool) ), SLOT(flipText()));
00115 
00116   action = new KToggleAction( i18n("&Reverse Direction"), this );
00117   action->setChecked(_rtl);
00118   actionCollection()->addAction( "rtl", action );
00119   connect(action, SIGNAL(toggled(bool) ), SLOT(setRtl(bool)));
00120 
00121   charSelect->setFocus();
00122 
00123   if(_rtl)
00124     lined->setAlignment( Qt::AlignRight );
00125   else
00126     lined->setAlignment( Qt::AlignLeft );
00127 
00128   setupGUI(Keys|Save|Create);
00129 }
00130 
00131 //==================================================================
00132 bool KCharSelectDia::queryExit()
00133 {
00134   KSharedConfig::Ptr config = KGlobal::config();
00135   KConfigGroup gr = config->group("General");
00136 
00137   gr.writeEntry("selectedFont", vFont);
00138   gr.writeEntry("char", static_cast<int>(vChr.unicode()));
00139   gr.writeEntry("rtl", _rtl);
00140 
00141   return true;
00142 }
00143 
00144 //==================================================================
00145 void KCharSelectDia::charChanged(const QChar &_chr)
00146 {
00147   vChr = _chr;
00148 }
00149 
00150 //==================================================================
00151 void KCharSelectDia::fontSelected(const QFont &_font)
00152 {
00153   lined->setFont( _font );
00154 
00155   vFont = _font;
00156 }
00157 
00158 //==================================================================
00159 void KCharSelectDia::add(const QChar &_chr)
00160 {
00161   charChanged(_chr);
00162 
00163   QString str = lined->text();
00164   int pos = lined->cursorPosition();
00165   str.insert(pos, _chr);
00166   lined->setText(str);
00167   lined->setCursorPosition(pos + 1);
00168 }
00169 
00170 //==================================================================
00171 void KCharSelectDia::toClip()
00172 {
00173   QClipboard *cb = QApplication::clipboard();
00174   cb->setText(lined->text(),QClipboard::Clipboard);
00175   cb->setText(lined->text(),QClipboard::Selection);
00176 }
00177 
00178 //==================================================================
00179 // UTF-8 is rapidly becoming the favored 8-bit encoding for
00180 // Unicode (iso10646-1).
00181 //
00182 void KCharSelectDia::toClipUTF8()
00183 {
00184   QClipboard *cb = QApplication::clipboard();
00185   QString str = lined->text();
00186   cb->setText(str.toUtf8());
00187 }
00188 
00189 //==================================================================
00190 //  Put valid HTML 4.0 into the clipboard.  Valid ISO-8859-1 Latin 1
00191 //  characters are left undisturbed.  Everything else, including the
00192 //  "c0 control characters" often used by Windows, are clipped
00193 //  as a HTML entity.
00194 //
00195 void KCharSelectDia::toClipHTML()
00196 {
00197   QClipboard *cb = QApplication::clipboard();
00198   QString input;
00199   QString html;
00200   QString tempstring;
00201   QChar   tempchar;
00202   int i;
00203 
00204   input = lined->text();
00205   for(i=0; i< input.length(); i++ )
00206     {
00207       tempchar = input.at(i);
00208       if(  tempchar.toLatin1() && ((tempchar.unicode() < 128) || (tempchar.unicode() >= 128+32)) )
00209         {
00210           html.append(input.at(i));
00211         }
00212       else
00213         {
00214           html.append(tempstring.sprintf("&#x%x;", tempchar.unicode()));
00215         }
00216     }
00217   cb->setText(html);
00218 }
00219 
00220 //==================================================================
00221 //
00222 void KCharSelectDia::fromClip()
00223 {
00224   QClipboard *cb = QApplication::clipboard();
00225   lined->setText( cb->text() );
00226 }
00227 
00228 //==================================================================
00229 // UTF-8 is rapidly becoming the favored 8-bit encoding for
00230 // Unicode (iso10646-1).  This function is handy for decoding
00231 // UTF-8 found in legacy applications, consoles, filenames, webpages,
00232 // etc.
00233 //
00234 void KCharSelectDia::fromClipUTF8()
00235 {
00236   QClipboard *cb = QApplication::clipboard();
00237   QString str = cb->text();
00238 
00239   lined->setText( str.fromUtf8( str.toLatin1() ) );
00240 }
00241 
00242 //==================================================================
00243 //  Reverse the text held in the line edit buffer.  This is crucial
00244 //  for dealing with visual vs. logical representations of
00245 //  right to left languages, and handy for working around all
00246 //  manner of legacy character order issues.
00247 //
00248 void KCharSelectDia::flipText()
00249 {
00250   QString input;
00251   QString output;
00252   int i;
00253 
00254   input = lined->text();
00255   for(i=0; i< input.length(); i++ )
00256     {
00257       output.prepend( input.at(i) );
00258     }
00259   lined->setText(output);
00260 }
00261 
00262 //==================================================================
00263 void KCharSelectDia::setRtl(bool rtl)
00264 {
00265     _rtl = rtl;
00266     if(_rtl)
00267         lined->setAlignment( Qt::AlignRight );
00268     else
00269         lined->setAlignment( Qt::AlignLeft );
00270 }
00271 
00272 //==================================================================
00273 void KCharSelectDia::lineEditChanged()
00274 {
00275     if(_rtl)
00276       {
00277         if(lined->cursorPosition())
00278             lined->setCursorPosition( lined->cursorPosition() - 1 );
00279       }
00280 }
00281 
00282 #include "kcharselectdia.moc"

kcharselect

Skip menu "kcharselect"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal