QColorButton详细加注释

QColorButton.h:
 
InBlock.gif /* 
InBlock.gif* Copyright (C) 2008/07/02 Florian Becker <[email]fb@pyades.com[/email]> 
InBlock.gif
InBlock.gif* The ownership of this document rests with the Pyades Technologies GmbH. 
InBlock.gif* It is strictly prohibited to change, sell or publish it in any way. In 
InBlock.gif* case you have access to this document, you are obligated to ensure its 
InBlock.gif* nondisclosure. Noncompliances will be prosecuted. 
InBlock.gif
InBlock.gif* Diese Datei ist Eigentum der Pyades Technologies GmbH. Ändern, verkaufen 
InBlock.gif* oder auf eine andere Weise verbreiten und Öffentlich machen ist strikt 
InBlock.gif* untersagt. Falls Sie Zugang zu dieser Datei haben, sind Sie verpflichtet 
InBlock.gif* alles Mögliche für deren Geheimhaltung zu tun. Zuwiderhandlungen werden 
InBlock.gif* strafrechtlich verfolgt. 
InBlock.gif*/
 
InBlock.gif 
InBlock.gif#ifndef QCOLORBUTTON_H 
InBlock.gif#define QCOLORBUTTON_H 
InBlock.gif 
InBlock.gif /* qt header */ 
InBlock.gif#include <QPushButton> 
InBlock.gif 
InBlock.gif /** 
InBlock.gif * Colorbutton,选择和显示实际的颜色. 
InBlock.gif * 
InBlock.gif * @brief Choose color via QPushButton and display it. 
InBlock.gif * @author Florian Becker (Pyades Technologies GmbH) <[email]fb@pyades.com[/email]> 
InBlock.gif * @date 2008/07/02 
InBlock.gif * @since 1.0.0 
InBlock.gif * @version 1.0.0 
InBlock.gif */
 
InBlock.gif class QColorButton :  public QPushButton { 
InBlock.gif 
InBlock.gif    Q_OBJECT 
InBlock.gif    Q_CLASSINFO(  "author""Florian Becker" ) 
InBlock.gif    Q_CLASSINFO(  "email""[email]fb@pyades.com[/email]" ) 
InBlock.gif    Q_CLASSINFO(  "company""Pyades Technologies GmbH" ) 
InBlock.gif    Q_CLASSINFO(  "link""http://www.pyades.com" ) 
InBlock.gif    Q_CLASSINFO( "date""2008/07/02" ) 
InBlock.gif 
InBlock.gifpublic
InBlock.gif    /** 
InBlock.gif     * QColorButton的缺省构造函数. 
InBlock.gif     * 
InBlock.gif     * @param parent - 父级widget. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    QColorButton( QWidget *parent = 0 ); 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 设置当前颜色. 
InBlock.gif     * 
InBlock.gif     * @param color -要设置的颜色. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    void setCurrentColor( const QColor &color ); 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 返回当前颜色. 
InBlock.gif     * 
InBlock.gif     * @return 当前颜色. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    inline QColor currentColor() const { return mCurrentColor; } 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 设置按钮文本. 
InBlock.gif     * 
InBlock.gif     * @param text     - 要设置的文本. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    void setText( const QString &text ); 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * Enable- 如果开启则显示用户定义的文本否则显示颜色值 
InBlock.gif     * 
InBlock.gif     * @param enableColorText -    True,则显示用户定义的文本;否则false显示颜色值. 
InBlock.gif     * 缺省为 true. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    void enableColorText( bool enableColorText ); 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 是否设置了用户定义文本还是颜色值? 
InBlock.gif     * 
InBlock.gif     * @如果设置用户定义文本则返回True;否则如果开启颜色值则返回false. 
InBlock.gif     *    
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    inline bool isColorTextEnabled() const { return mEnableColorText; } 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * Enable-显示颜色值的ToolTip. 
InBlock.gif     * 
InBlock.gif     * @param enableToolTip    - True, 开启显示颜色值的ToolTip - 没开启为false 
InBlock.gif     * 缺省为true. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    void enableToolTip( bool enableToolTip ); 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 颜色值显示的tooltip是否开启? 
InBlock.gif     * 
InBlock.gif     * @return True,-如果开启 - 否则 false. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    inline bool isToolTipEnabled() const { return mEnableToolTip; } 
InBlock.gif 
InBlock.gifprivate
InBlock.gif    /** 
InBlock.gif     * Intern function to set the new or changed color value as text. 
InBlock.gif     * 
InBlock.gif     * @param colorText     The color value as text. 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    void setColorText( const QString &colorText ); 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     *颜色文本是否开启? 
InBlock.gif     * 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    bool mEnableColorText; 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 是否开启了color Tooltip? 
InBlock.gif     * 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    bool mEnableToolTip; 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 当前颜色. 
InBlock.gif     * 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    QColor mCurrentColor; 
InBlock.gif 
InBlock.gif    /** 
InBlock.gif     * 实际的文本. 
InBlock.gif     * 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    QString mRealText; 
InBlock.gif 
InBlock.gifprivate slots: 
InBlock.gif    /** 
InBlock.gif     * 内部slot用来调用colordialog并修改颜色 
InBlock.gif     * 
InBlock.gif     * @since 1.0.0 
InBlock.gif     */
 
InBlock.gif    void slotChangeColor(); 
InBlock.gif}; 
InBlock.gif 
InBlock.gif#endif 
 
 
QColorButton.cpp:
 
InBlock.gif /* 
InBlock.gif* Copyright (C) 2008/07/02 Florian Becker <[email]fb@pyades.com[/email]> 
InBlock.gif
InBlock.gif* The ownership of this document rests with the Pyades Technologies GmbH. 
InBlock.gif* It is strictly prohibited to change, sell or publish it in any way. In 
InBlock.gif* case you have access to this document, you are obligated to ensure its 
InBlock.gif* nondisclosure. Noncompliances will be prosecuted. 
InBlock.gif
InBlock.gif* Diese Datei ist Eigentum der Pyades Technologies GmbH. Ändern, verkaufen 
InBlock.gif* oder auf eine andere Weise verbreiten und Öffentlich machen ist strikt 
InBlock.gif* untersagt. Falls Sie Zugang zu dieser Datei haben, sind Sie verpflichtet 
InBlock.gif* alles Mögliche für deren Geheimhaltung zu tun. Zuwiderhandlungen werden 
InBlock.gif* strafrechtlich verfolgt. 
InBlock.gif*/
 
InBlock.gif 
InBlock.gif /* qt header */ 
InBlock.gif#include <QColorDialog> 
InBlock.gif 
InBlock.gif /* local header */ 
InBlock.gif#include  "QColorButton.h" 
InBlock.gif 
InBlock.gifQColorButton::QColorButton( QWidget *parent ) 
InBlock.gif        : QPushButton( parent ), 
InBlock.gif        mEnableColorText(  true ), 
InBlock.gif        mEnableToolTip(  true ) { 
InBlock.gif 
InBlock.gif    connect(  this, SIGNAL( clicked() ), SLOT( slotChangeColor() ) ); //如果单击按钮执行slotChangeColor 
InBlock.gif    setCurrentColor(  "#ffffff" ); 
InBlock.gif
InBlock.gif 
InBlock.gif //设置当前颜色 
InBlock.gif void QColorButton::setCurrentColor(  const QColor ¤tColor ) { 
InBlock.gif 
InBlock.gif     //如果没有改变颜色则返回 
InBlock.gif     if ( mCurrentColor == currentColor ) 
InBlock.gif         return
InBlock.gif 
InBlock.gif    mCurrentColor = currentColor; //更新mCurrentColor变量 
InBlock.gif     if ( mEnableColorText ) 
InBlock.gif        setColorText( mCurrentColor.name() ); //如#336699 
InBlock.gif     if ( mEnableToolTip ) 
InBlock.gif        setToolTip( mCurrentColor.name() ); 
InBlock.gif         
InBlock.gif    QPixmap pix( 16, 16 ); //16*16 
InBlock.gif    pix.fill( mCurrentColor ); //用当前色填充 
InBlock.gif    setIcon( pix ); //设置按钮图标 
InBlock.gif
InBlock.gif 
InBlock.gif void QColorButton::setText(  const QString &text ) { 
InBlock.gif 
InBlock.gif     if ( mRealText == text ) 
InBlock.gif         return
InBlock.gif 
InBlock.gif    mRealText = text; 
InBlock.gif    QPushButton::setText( mRealText ); 
InBlock.gif
InBlock.gif 
InBlock.gif //开启颜色值文本 
InBlock.gif void QColorButton::enableColorText(  bool enableColorText ) { 
InBlock.gif 
InBlock.gif     if ( mEnableColorText == enableColorText ) 
InBlock.gif         return
InBlock.gif 
InBlock.gif    mEnableColorText = enableColorText; 
InBlock.gif     if ( mEnableColorText ) 
InBlock.gif        setColorText( mCurrentColor.name() ); 
InBlock.gif     else 
InBlock.gif        setText( mRealText ); 
InBlock.gif
InBlock.gif 
InBlock.gif //开启tooltip 
InBlock.gif void QColorButton::enableToolTip(  bool enableToolTip ) { 
InBlock.gif 
InBlock.gif     if ( mEnableToolTip == enableToolTip ) 
InBlock.gif         return
InBlock.gif 
InBlock.gif    mEnableToolTip = enableToolTip; 
InBlock.gif     if ( mEnableToolTip ) 
InBlock.gif        setToolTip( mCurrentColor.name() ); //设置tooltip为颜色值 
InBlock.gif     else 
InBlock.gif        setToolTip( "" ); 
InBlock.gif
InBlock.gif 
InBlock.gif //设置颜色文本 
InBlock.gif void QColorButton::setColorText(  const QString &colorText ) { 
InBlock.gif 
InBlock.gif     //如果文本没有改变则返回 
InBlock.gif     if ( text() == colorText ) 
InBlock.gif         return
InBlock.gif 
InBlock.gif    QPushButton::setText( colorText ); //明确调用父类的方法 
InBlock.gif
InBlock.gif 
InBlock.gif //自定义的slot 
InBlock.gif void QColorButton::slotChangeColor() { 
InBlock.gif 
InBlock.gif     //弹出颜色对话框,初始值设置为mCurrentColor 
InBlock.gif    QColor newColor = QColorDialog::getColor( mCurrentColor,  this ); 
InBlock.gif     if ( newColor.isValid() ) 
InBlock.gif        setCurrentColor( newColor ); //如果颜色值合法 
InBlock.gif


本文转自 xcf007 51CTO博客,原文链接: http://blog.51cto.com/xcf007/104778 ,如需转载请自行联系原作者



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值