2010年11月1日 星期一

Qt: QRegion Class 圖形交疊的四種取出作法

Creating and Using Regions

當在Qt使用QPainter繪圖時,常常會遇到所需繪出圖形並非單純的長方形(Rectangle)或多邊形(polygon),可能是多種圖形的交錯合體情況,以下說明當圖形重疊時,可取得相交區域的四種情形。

General Usage:
void MyWidget::paintEvent(QPaintEvent *)
{
    QRegion r1(QRect(100, 100, 200, 80), QRegion::Ellipse);
    // r1: elliptic region
    QRegion r2(QRect(100, 120, 90, 30));    // r2: rectangular region
    QRegion r3 = r1.intersected(r2);        // r3: intersection
    QPainter painter(this);
    painter.setClipRegion(r3);
    ...                                     // paint clipped graphics
    painter.drawrect(QRect(100, 100, 200, 80));
}

  1. 交集-僅取出兩者相疊區域(intersected):
    • QRegion QRegion::intersected ( const QRegion & r ) const
    • 圖例:
  2. 僅取出前者未與後者重疊區域(subtracted):
    • QRegion QRegion::subtracted ( const QRegion & r ) const
    • 圖例:
  3. 聯集-合併取出兩者所有區域(united):
    • QRegion QRegion::united ( const QRegion & r ) const
    • 圖例:
  4. 取出兩者不重疊的區域(xored):
    • QRegion QRegion::xored ( const QRegion & r ) const
    • 圖例:



更詳細資料請參考:Qt4.6 QRegion Class Reference

2010年10月22日 星期五

讓Putty能夠顯示中文字 in Ubuntu

在Ubuntu下,要讓Putty顯示中文字主要設定方式可分為兩個步驟

  • 設定Putty Translation編碼,如下圖所示
    1. 選擇 Translation >> Remote character set: UTF-8

  • 設定Putty window Fonts,如下圖所示
    1. 選擇 Fonts >> 按下 Font used for ordinary text (Change...)
    2. 選擇字型 "TlwgMono"

大功告成!


--- 特別感謝 David 技術教學 ---

2010年10月19日 星期二

Colorful man pages setting

  • Linux colorful man pages setting (for bash)
    • 開啟個人bash設定檔
    vi ~/.bashrc
  • 加入以下資料
  • # For colourful man pages
    export PAGER="`which less` -s"
    export BROWSER="$PAGER"
    export LESS_TERMCAP_mb=$'\E[01;34m'
    export LESS_TERMCAP_md=$'\E[01;34m'
    export LESS_TERMCAP_me=$'\E[0m'
    export LESS_TERMCAP_se=$'\E[0m'
    export LESS_TERMCAP_so=$'\E[01;44;33m'
    export LESS_TERMCAP_ue=$'\E[0m'
    export LESS_TERMCAP_us=$'\E[01;33m'
    
  • 讀取bash設定檔
  • source ~/.bashrc
  • 完成!