lfpport_qte_choicegroup.h

来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 1,394 行 · 第 1/3 页

H
1,394
字号
/* *    * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, 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 version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. *  * This source file is specific for Qt-based configurations. *//** * @file * Qt port of ChoiceGroup. */#ifndef _LFPPORT_QTE_CHOICEGROUP_H_#define _LFPPORT_QTE_CHOICEGROUP_H_#include <lfpport_choicegroup.h>#include "lfpport_qte_item.h"#include <qvbuttongroup.h>#include <qlistbox.h>#include <qpushbutton.h>#include <qlist.h>#include "lfpport_qte_patched.h"/** * Constant for an exclusive-choice list or choice group. Its value is * defined in the <i>MIDP Specification</i>. */#define EXCLUSIVE 1/** * Constant for a multiple-choice list or choice group. Its value is * defined in the <i>MIDP Specification</i>. */#define MULTIPLE  2/** * Constant for an implicit list. Its value is defined in the <i>MIDP * 2.0 Specification</i>. */#define IMPLICIT  3/** * Constant for a pop-up choice group. Its value is defined in the * <i>MIDP Specification</i>. */#define POPUP     4/** * Constant for requesting the device's default text-wrapping policy * for the elements of the list or choice group.  Its value is defined * in the <i>MIDP Specification</i>. */#define TEXT_WRAP_DEFAULT 0/** * Constant for requesting text wrapping for for the elements of the * list or choice group with content longer than one line.  Its value * is defined in the <i>MIDP Specification</i>. */#define TEXT_WRAP_ON      1/** * Constant for requesting that text wrapping not be used for for the * elements of the list or choice group with content longer than one * line.  Its value is defined in the <i>MIDP Specification</i>. */#define TEXT_WRAP_OFF     2/** * Maximum width to be used for choicegroup image. * If image is wider it will be clipped to this width */#define PREF_IMG_WIDTH 12/** * Maximum height to be used for choicegroup image. * If image is taller and text occupies less height  * image will be clipped to this height. */#define PREF_IMG_HEIGHT 12/** * Shared class for all types of ChoiceGroup's widget. */class Choice : public Item {  Q_OBJECT   public :    /**     * Construct a ChoiceGroup widget.     *     * @param parent owner form's widget     * @param label label text     * @param fitPolicy text wrapping policy     * @param alwaysVertLayout true if label should always be on     *		a separated line from the body     */    Choice(QWidget *parent, const QString &label, int layout = 0,	   int fitPolicy = 0, bool alwaysVertLayout = true);    /**     * Destruct this widget.     */    virtual ~Choice();    /**     * Handle user events.     * Since Qt uses SIGNAL/SLOT to deliver events directly,      * this function is not used.     *     * @param eventPtr event to handle     * @return true if no further handling is needed     */    virtual jboolean  handleEvent(QEvent *eventPtr);    /**     * Insert an element.     *     * @param elementNum index of the inserted element     * @param str text portion     * @param img image portion     * @param selected selection state     * @return status of this call     */    virtual MidpError insert(int elementNum, const QString &str, QPixmap* img, 			     jboolean selected) = 0;    /**     * Delete an element.     *     * @param elementNum index of the to-be deleted element     * @param selectedIndex element to select after deletion     * @return status of this call     */    virtual MidpError deleteElement(int elementNum, int selectedIndex) = 0;    /**     * Remove all elements.     * @return status of this call     */    virtual MidpError deleteAll() = 0;    /**     * Update an element with new text, image and selection state.     *     * @param elementNum index of the element     * @param str new text     * @param img new image     * @param selected new selection state     * @return status of this call     */    virtual MidpError set(int elementNum, const QString &str, QPixmap* img, 			  jboolean selected) = 0;    /**     * Set selection state for an element.     *     * @param elementNum index of the element     * @param selected new selection state     * @return status of this call     */    virtual MidpError setSelectedIndex(int elementNum, jboolean selected) = 0;    /**     * Get current selected element.     *     * @param elementNum return the index of the currently selected element     * @return status of this call     */    virtual MidpError getSelectedIndex(int *elementNum) = 0;    /**     * Set selection state for all elements.     *     * @param selectedArray array with selection states     * @param arrayLength size of the array     * @return status of this call     */    virtual MidpError setSelectedFlags(jboolean* selectedArray,				       int arrayLength) = 0;    /**     * Get the selection state of all the elements.     *     * @param numSelected return the number of selected elements     * @param selectedArray array to store returned selection states     * @param arrayLength size of the array     * @return status of this call     */    virtual MidpError getSelectedFlags(int *numSelected,				       jboolean* selectedArray,				       int arrayLength) = 0;    /**     * Get the selection state of an element.     *     * @param selected return state     * @param elementNum index of the element     * @return status of this call     */    virtual MidpError isSelected(jboolean *selected, int elementNum) = 0;    /**     * Set the text wrapping policy.     *     * @param fitPolicy TEXT_WRAP_ON, TEXT_WRAP_OFF or TEXT_WRAP_DEFAULT     * @return status of this call     */    virtual MidpError setFitPolicy(int fitPolicy) = 0;    /**     * Set font of an element     *     * @param elementNum index of the element     * @param new font     * @return status of this call     */    virtual MidpError setFont(int elementNum, QFont *font) = 0;    /**     * Returns currently set fit policy.     * @return fitPolicy currently set     */    int getFitPolicy(); protected:    /**     * Text wrapping policy.     * TEXT_WRAP_ON or TEXT_WRAP_OFF.     */    int fitPolicy;};/** * Returns currently set fit policy in Choice * @return fitpolicy currently set in Choice */inline int Choice::getFitPolicy() { return fitPolicy; }//*******************************************************************/** * Widget for choice elements of EXCLUSIVE and MULTIPLE ChoiceGroups. * Extend QButton to support text wrapping and image. */class ChoiceButton : public QButton {  Q_OBJECT private:  /**   * Whether it is part of an exclusive group.   */  bool isExclusive;  /**   * Image to show.   */  QPixmap *img;   /**   * Size of the image.   */  QSize imgSize;  /**   * Text wrapping policy.   */  int fitPolicy; protected:  /**   * Override QButton to notify Java peer of new selection.   *   * @param keyEvent key event to handle   */  void keyPressEvent(QKeyEvent *keyEvent);  /**   * Override QButton to notify Java peer of traversal out.   *   * @param keyEvent key event to handle   */  void keyReleaseEvent(QKeyEvent *keyEvent);  /**   * Override QButton to notify Java peer of new selection.   *   * @param mouseEvent key event to handle   */  void mouseReleaseEvent(QMouseEvent *mouseEvent);  /**   * Makes this item have focus, enabling any item-specific commands; in   * addition, if the given event was caused by a user action, notifies the   * Java platform of the change in focus.   *   * @param event pointer to the device event corresponding to the change in   *        focus.   */  void focusInEvent(QFocusEvent *event);  /**   * Override QButton to custom paint wrapped text and image.   *   * @param painter painter to use   */  void drawButton(QPainter * painter); public:  /**   * Construct a choice button.   *   * @param str text portion   * @param img image portion   * @param parent containing choicegroup body widget   * @param isExclusive whether it's part of an exclusive group   * @param fitPolicy text wrapping policy   */  ChoiceButton(const QString &str, QPixmap* img, QWidget *parent,                bool isExclusive, int fitPolicy);  /**   * Destruct a Choice Button widget.   */  virtual ~ChoiceButton();  /**   * A public method to set a button to on or off.   *   * @param check whether it should be shown as selected   */  void setChecked( bool check ) { setOn( check ); }  /**   * Override QButton to calculate size based on its contents.   *   * @return size needed to show this button   */  QSize sizeHint() const;  /**   * Size calculation based on the width available    *   * @param w the width available for this ChoiceButton   * @return size needed to show this button in the passed in width   */  QSize sizeHint(int w) const;  /**   * Update this button with new image.   *   * @param pixmap new image   */  void setImage(QPixmap *pixmap); public slots:  /**   * Notify Java peer that its selection state has changed.   *   */  void notifyStateChanged();  /**   * Change text wrapping policy.   *   * @param fitPolicy new policy   */  void setFitPolicy(int fitPolicy);};//***************************************************************/** * Body widget for MULTIPLE and EXCLUSIVE ChoiceGroup. */class ChoiceButtonBoxBody : public QVButtonGroup { public:  /**   * Create a body widget.   *   * @param parent ChoiceGroup widget   */  ChoiceButtonBoxBody(QWidget *parent);  /**   * ChoiceButtonBoxBody destructor   */  virtual ~ChoiceButtonBoxBody();  /**   * Override QButtonGroup to traverse between choice elements.   *   * @param key key user pressed   */  void moveFocus(int key);  /**    * Override QButtonGroup to return the first choice that is selected.   *   * @return first choice selected   */  ChoiceButton *selected();  /**   * Size calculation based on the width available.   *    * @param w the width available for this ChoiceButtonBoxBody   * @return the size of the button base on the fixed width   */  QSize sizeHint(int w) const;  /**   * Override QVButtonGroup to fix width for ChoiceButtons before   * internal layout happens.   *   * @param w the new width of this ChoiceButtonBoxBody   * @param h the new height of this ChoiceButtonBoxBody   */  void resize(int w, int h); protected:  /**   * Makes this item have focus, enabling any item-specific commands; in   * addition, if the given event was caused by a user action, notifies the   * Java platform of the change in focus.   *   * @param event pointer to the device event corresponding to the change in   *        focus.   */  void focusInEvent(QFocusEvent *event);};/** * Body widget for IMPLICIT List. */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?