[Patch] KQADialog.cpp/h

Carsten Niehaus <[email protected]> Tue, 17 Feb 2004 16:53:57 +0100
Newsgroups gmane.comp.tools.memaid.devel
Message-ID <[email protected]>
--Boundary-00=_VkjMAjFPHsNrY9W
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi

I send this patch yesterday but still don't see it on the list. Either my or 
sf's setup is borked. Whatever: Here is the patch again:

* I improved the code and added comments whereever I changed the code. Please 
remove the comments before commiting.
* I added some buttons + the corresponding code to the Dialog where you enter 
the questions+answers. I hope you like it.

I have no access to the cvs so I can't commit myself.

Carsten

-- 
Carsten Niehaus

--Boundary-00=_VkjMAjFPHsNrY9W
Content-Type: text/x-diff;
  charset="us-ascii";
  name="kqadialog.cpp.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="kqadialog.cpp.diff"

--- kmemaid_diff/kqadialog.cpp	2004-01-28 21:28:41.000000000 +0100
+++ kmemaid/kqadialog.cpp	2004-02-13 16:38:48.000000000 +0100
@@ -2,7 +2,7 @@
                           kqadialog.cpp  -  description
                              -------------------
     begin                : Sam Aug 23 2003
-    copyright            : (C) 2003 by Klemens Meyer
+    copyright            : (C) 2003, 2004 by Klemens Meyer
     email                : [email protected]
  ***************************************************************************/
 
@@ -19,8 +19,15 @@
 #include <klocale.h>
 #include <qvbox.h>
 #include <kpushbutton.h>
+#include <kdebug.h>
 #include <qlabel.h>
 #include <kmessagebox.h>
+#include <kfiledialog.h>
+#include <qfontdialog.h>
+#include <qwhatsthis.h>
+
+#include <iostream>
+using namespace std;
 
 
 
@@ -31,33 +38,70 @@
 	, corr_close(!adding && el)
 {
 	QVBox*	page	= makeVBoxMainWidget();
+	QHBox*	toolb	= new QHBox(page);
 
-    QHButtonGroup*  qbox    = new QHButtonGroup(i18n("Question"), page, "questiongroup");
-    QHButtonGroup*  abox    = new QHButtonGroup(i18n("Answer"), page, "answergroup");
+	QHButtonGroup*  qbox    = new QHButtonGroup(i18n("Question"), page, "questiongroup");
+	QHButtonGroup*  abox    = new QHButtonGroup(i18n("Answer"), page, "answergroup");
 
+	/*
+	 * why this ctor?
+	 * 
 	question	= new KTextEdit("", QString::null, qbox, "question");
 	answer		= new KTextEdit("", QString::null, abox, "answer");
-
+	*/
+	
+	question	= new KTextEdit(qbox, "question");
+	answer		= new KTextEdit(abox, "answer");
+	
+	/*
+	 * new Element
+	 */
 	if(adding)
 	{
 		viceversa	= new QCheckBox(i18n("Add Vice Versa too"), page, "viceversa");
 		grades		= new QHButtonGroup(i18n("Grade Select"), page, "GradeSelect");
+		m_boldButton	= new KPushButton(i18n("Bold") , toolb , "boldButton");
+		m_hlineButton	= new KPushButton(i18n("Horizontal Line") , toolb , "hlineButton");
+		m_imageButton	= new KPushButton(i18n("Insert Image") , toolb , "imageButton");
+		m_fontButton	= new KPushButton(i18n("Insert Font") , toolb , "fontMetrics");
+	
+		connect(grades, SIGNAL(clicked(int)), this, SLOT(newGrade(int)));
+		connect( m_boldButton , SIGNAL(clicked()), this, SLOT(slotMakeTextBold()) );
+		connect( m_imageButton , SIGNAL(clicked()), this, SLOT(slotInsertImage()) );
+		connect( m_hlineButton , SIGNAL(clicked()), this, SLOT(slotInsertHLine()) );
+		connect( m_fontButton , SIGNAL(clicked()), this, SLOT(slotInsertFont()) );
+		/*
+		 * adding some help for the user
+		 */
+		QWhatsThis::add(viceversa, i18n("If this checkbox is selected KMemAid will ask this in both directions"));
+		QWhatsThis::add(m_boldButton, i18n("A click on this button puts the tags for bold text around the selected text."));
+		QWhatsThis::add(m_hlineButton, i18n("A click on this button add a horizontal line to the current cursor position."));
+		QWhatsThis::add(m_imageButton, i18n("A click on this button will open a dialog in which an image can be selected."));
+		QWhatsThis::add(m_fontButton, i18n("A click on this button will open a dialog in which a font for the selected text can be choosen."));
 
+			
 		for(int i = 0 ; i < 6 ; ++i)
 		{
+			/*
+			 * sprintf should not be used in KDE-apps.
+			 * Use title.arg() instead or QString::number()
+			
 			QString	title;
 			title.sprintf("%d", i);
+			*/
+			QString	title = QString::number(i);
 
-			KPushButton*	pb	= new KPushButton(title, grades, title);
+			KPushButton* pb	= new KPushButton(title, grades, title);
 			pb->setAccel(QKeySequence(title));
 		}
 		grades->setFixedHeight(grades->sizeHint().height());
 
-		connect(grades, SIGNAL(clicked(int)), this, SLOT(newGrade(int)));
-
 		statusBar	= new KStatusBar(page, "status");
-		statusBar->insertItem(i18n("Type question and answer, then choose an initial Grade (5 is the best)."), 0, 1);
+		statusBar->insertItem(i18n("Type question and answer, then choose an initial Grade (5 is the best)."), 0, true);
 	}
+	/*
+	 * find a element
+	 */
 	else
 	{
 		QHBox*	box	= new QHBox(page, "findbox");
@@ -70,16 +114,13 @@
 		statusBar	= new KStatusBar(page, "status");
 		statusBar->insertItem(i18n("Type question and/or answer, then click on find."), 0, 1);
 	}
-
 	question->setTabChangesFocus(true);
 	answer->setTabChangesFocus(true);
-
 	if(element)
 	{
 		question->setText(QString::fromLocal8Bit(element->q));
 		answer->setText(QString::fromLocal8Bit(element->a));
 	}
-
 }
 
 KQADialog::~KQADialog()
@@ -148,3 +189,67 @@
 	question->setFont(q);
 	answer->setFont(a);
 }
+
+KTextEdit* KQADialog::activeKTE() const
+{
+	if(question->hasFocus())
+		return question;
+	else
+		return answer;
+}
+
+void KQADialog::slotInsertFont()
+{
+	cout << "slotINsertFont()" << endl;
+	bool ok;
+	QFont font = QFontDialog::getFont(
+			&ok, QFont( "Helvetica [Cronyx]", 10 ), this );
+	if ( ok ) 
+	{
+		KTextEdit *kte = activeKTE();
+		QString sel = activeKTE()->selectedText();
+		
+		cout << "Auswahl:" << endl;
+	cout << "Auswahl ist: " << sel << endl;
+		
+		QString fontname = font.family();
+		fontname.prepend("<font face=\"");
+		fontname.append("\">");
+		sel.prepend(fontname);
+		sel.append("</font>");
+		// font is set to the font the user selected
+		kte->insert(sel);	
+	} 
+}
+
+void KQADialog::slotInsertImage()
+{
+
+	/*
+	 * for some reasons the activeKTE() changes after the
+	 * getOpenFileName(). Thus, we determine it before getting
+	 * the filename...
+	 */
+	
+	KTextEdit* kte = activeKTE();
+	QString s = KFileDialog::getOpenFileName();
+	s.prepend("<img src=\"");
+	s.append("\">");
+	kte->insert(s);
+}
+
+void KQADialog::slotInsertHLine()
+{
+	activeKTE()->insert("<hr />");
+}
+
+void KQADialog::slotMakeTextBold()
+{
+	QString sel = activeKTE()->selectedText();
+	
+	sel.prepend("<b>");
+	sel.append("</b>");
+
+	activeKTE()->insert(sel);
+}
+

--Boundary-00=_VkjMAjFPHsNrY9W
Content-Type: text/x-diff;
  charset="us-ascii";
  name="kqadialog.h.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="kqadialog.h.diff"

--- kmemaid_diff/kqadialog.h	2004-01-28 21:28:41.000000000 +0100
+++ kmemaid/kqadialog.h	2004-02-13 16:27:00.000000000 +0100
@@ -1,9 +1,9 @@
 /***************************************************************************
-                          kqadialog.h  -  description
-                             -------------------
-    begin                : Sam Aug 23 2003
-    copyright            : (C) 2003 by Klemens Meyer
-    email                : [email protected]
+		kqadialog.h  -  description
+		-------------------
+		begin                : Sam Aug 23 2003
+		copyright            : (C) 2003, 2004 by Klemens Meyer
+		email                : [email protected]
  ***************************************************************************/
 
 /***************************************************************************
@@ -28,45 +28,50 @@
 #include "memaid/memaid.h"
 
 
-/**Dialog for input/correction of new elements
-  *@author Klemens Meyer
-  */
-
 class KQADialog : public KDialogBase
 {
-   Q_OBJECT
-public:
-
-	KQADialog(bool adding, const QString& caption, QWidget *parent=0, const char *name=0, elem* el = NULL);
-	~KQADialog();
+	Q_OBJECT
+	public:
 
-private:
+		KQADialog(bool adding, const QString& caption, QWidget *parent=0, const char *name=0, elem* el = NULL);
+		~KQADialog();
 
-	void Init();
-
-private:
-
-	KStatusBar*		statusBar;
-	KTextEdit*		question;
-	KTextEdit*		answer;
-	QCheckBox*		viceversa;
-	QHButtonGroup*	grades;
-	KPushButton*	fcbutton;
-	int				ngrade;
-	elem*			element;
-	bool			corr_close;
-
-signals: // Signals
-  /** No descriptions */
-  void newQuestion(const QString& question, const QString& answer, int grade);
-public slots: // Public slots
-  /** Select the new Grade */
-  void newGrade(int grade);
-  /** Finding and correcting of elements */
-  void findCorrect();
-  /** Setting the Font for the input-fields */
-  void setFonts(const QFont& q, const QFont& a);
-//Del by KDevelop: 
+	private:
+		void Init();
+		KTextEdit* activeKTE() const;
+
+	private:
+
+		KStatusBar*		statusBar;
+		KTextEdit*		question;
+		KTextEdit*		answer;
+		QCheckBox*		viceversa;
+		QHButtonGroup*	grades;
+		KPushButton*	fcbutton;
+		KPushButton	*m_boldButton,
+				*m_hlineButton,
+				*m_imageButton,
+				*m_fontButton;
+		int				ngrade;
+		elem*			element;
+		bool			corr_close;
+
+	signals: // Signals
+		/** No descriptions */
+		void newQuestion(const QString& question, const QString& answer, int grade);
+		public slots: // Public slots
+		/** Select the new Grade */
+		void newGrade(int grade);
+		/** Finding and correcting of elements */
+		void findCorrect();
+		/** Setting the Font for the input-fields */
+		void setFonts(const QFont& q, const QFont& a);
+
+	private slots:
+		void slotMakeTextBold();
+		void slotInsertImage();
+		void slotInsertFont();
+		void slotInsertHLine();
 };
 
 #endif

--Boundary-00=_VkjMAjFPHsNrY9W--



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click