More neat stuff

Chris Hawks <[email protected]> Fri, 22 Feb 2002 16:21:24 -0500 (EST)
Newsgroups gmane.comp.web.viewml.devel
Message-ID <[email protected]>
I found that I needed the comboboxes in viewml to stay open (like other
browser's do), so I changed qcombobox to extend Fl_Menu_button instead of
Fl_Choice. It works well. The qcombobox.h is attached.

                                Chris

Christopher R. Hawks Software Engineer
Syscon Plantstar a Division of Syscon International
-------------------------------------------------------------------------
"In the beginning there was nothing... which exploded."
    -- The shortened Big Bang theory

#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[email protected]>.
To unsubscribe, E-mail to: <[email protected]>
To switch to the DIGEST mode, E-mail to <[email protected]>
To switch to the INDEX mode, E-mail to <[email protected]>
Send administrative queries to  <[email protected]>
qcombobox.h (application/octet-stream, 1.9 KB)
#ifndef __QCOMBOBOX_H
#define __QCOMBOBOX_H

/*	Rewritten Chris Hawks 22 Feb 2002
 *	to use Fl_Menu_Button instead of Fl_Choice so widget stays open.
 */

#include "qstring.h"
#include "qwidget.h"
#include "Fl_Menu_Button.H"

#define QCOMBO_HEIGHT 20
#define QCOMBO_PADDING 50

static void cb_combo(Fl_Widget * o, void * pThis);

class QComboBox : public QWidget
	{
	Q_OBJECT;

protected:
	Fl_Menu_Button * m_pCombo;
	int m_nCount;
public:
	QComboBox(bool rw, QWidget * parent = 0, const char *name = 0)
												:QWidget(parent, name)
		{
		m_nCount = 0;
		QWidget::setMinimumSize(40, 20);
		m_pCombo = new Fl_Menu_Button(0, 0, 40, 20, NULL);
		m_pCombo->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
		m_pCombo->callback((Fl_Callback * ) cb_combo, this);
		setWidget(m_pCombo);
		}
	int count() const
		{
		return m_nCount;
		}
	void insertItem(const QString & text, int index =  - 1)
		{
		m_nCount++;

		if (!text.length())
			{
			m_pCombo->add(" ");
			_change_size(text);
			}
		else
			{
			m_pCombo->add(text);
			_change_size(text);
			}
		}

	void _change_size(const QString & text)
		{
		m_pCombo->textfont(m_Font.getFont());
		m_pCombo->textsize(m_Font.size());
		m_pCombo->label(m_pCombo->text());
		m_pCombo->labelfont(m_Font.getFont());
		QFontMetrics fm(m_Font);
		if (sizeHint() .width() < fm.width(text) + QCOMBO_PADDING)
			QWidget::setMinimumSize(fm.width(text) + QCOMBO_PADDING, 
				fm.height() + 6);
		QWidget::resize(sizeHint());
		}

	void setCurrentItem(int index)
		{
		m_pCombo->value(index);
		}

	int getCurrentItem()
		{
		return m_pCombo->value();
		}

	void changeItem(const QString & text, int index)
		{
		m_pCombo->replace(index, text);
		_change_size(text);
		}
	void _callback();
signals:
	void changed();
	};

void QComboBox::_callback()
	{
	emit changed();
	}

static void cb_combo(Fl_Widget * o, void * pThis)
	{
	((QComboBox *) pThis)->_callback();
	}

#include "qcombobox.moc"
#endif