2009年6月30日 星期二

用Qt Creator設計元件隨視窗改變大小

設計元件中layouts,就是我們要的,先把這些擺好,譬如要擺一組6個水平button,就加一個horizontal Layout,再把6個button丟進去,OK後在主frame按右鍵->Lay out -> Lay out in a grid這樣就大功告成.(如下圖)





























read more...

2009年6月28日 星期日

用Qt Creator加上背景圖案

1.必須先增加Resource file.(New->Qt->Resource file)
2.在
Resource file點Add->Add Prefix->Add->Add Files->選背景圖
3.File->Save All
4.mainwindow.ui右下視窗有->styleSheet->Add Resource->background-images(小箭頭)->Reload一下
->選圖檔,大功告成

把背景換成kitty的圖案

read more...

2009年6月25日 星期四

xmms2_v2.1播放介面發佈

修正一些BUG,可聽線上廣播

下載xmms2_v2.1播放介面(ubuntu9.04)

下載xmms2_v2.1播放介面(debian5.0)->因為debian qt還不是最新,拉桿會失效,只能用滑鼠滾輪



畫面




read more...

2009年6月19日 星期五

Qt寫的Xmms2播放介面第一版發布.

最新的,看起來有點像樣了,可聽線上廣播,新增時鐘,可調音量,多增一個列表區,面板和按鈕作一些調整,還沒上傳,等在調整好一些在上傳,debian5.0,和ubuntu9.04測試OK,其他版LINUX應該也OK.






























































據續上篇,把空格檔名無法加入xmms2 list,和一些小BUG解掉,增加暫停,添加功能,自動從使用者展開檔案tree,滑鼠小提示.
添加歌曲改成用下面,空格檔名就能加到xmms2 list,試很久才成功
---------------------------------------------------------------------------------
QProcess *myP = new QProcess(this); //宣告QProcess
QStringList arguments;
arguments << "add" <<>

---------------------------------------------------------------------------------
取得user name我在網路上找到,修改一下user_name.replace("\n",""),必須去掉換行,試很久才成功
--------------------------------------------------------------------------------

char text[255];
//FILE *name;
FILE *name;
name = popen("whoami", "r");
fgets(text, sizeof(text), name);
pclose(name);
user_name=text; //使用者name
user_name=user_name.replace("\n",""); //要把換行去掉
user_path = "/home/"+user_name.replace("\n",""); //使用者目錄
----------------------------------------------------------------------------------

開放原碼:

xmms2播放介面下載(new)


來幾張執行結果:















































這張是加了Icon比較漂亮(要先取得Qt執行檔位置,加icon才不會跑掉)

strPath = QApplication::applicationDirPath();//Qt取得執行檔位置

















把介面弄好看一些,加上顯示正在播放歌曲,即時時間,這部份要寫接收信號,搞很久才成功,進度顯示棒還沒完成,比之前那版好多了.
















進度棒也寫好了,主要是處理接收xmms2 status 的信號後,要如何得到一首歌共幾秒,和目前播到第幾秒,QRegExp 是Qt正規表示很像bash shell的正規表示,然後用replace換掉就可得到想要的.





void MainWindow::progressBar_step_set(QString str)
{
QString strx1=str;
QString strx2=str;
QRegExp rx1(" of .*$");
QRegExp rx2("^.* of ");
QString timer_set_str=strx1.replace(rx1,"");
QString timer_max_str=strx2.replace(rx2,"");
QRegExp mrx(":.*$");
QRegExp srx("^.*:");
QString m_timer_set_str=timer_set_str;
QString s_timer_set_str=timer_set_str;
QString msrt_set=m_timer_set_str.replace(mrx,""); //minute_set
QString ssrt_set=s_timer_set_str.replace(srx,""); //second_set
QString m_timer_max_str=timer_max_str;
QString s_timer_max_str=timer_max_str;
QString msrt_max=m_timer_max_str.replace(mrx,""); //minute_max
QString ssrt_max=s_timer_max_str.replace(srx,""); //second_max
int m_set = m_timer_set_str.toInt();
int s_set = s_timer_set_str.toInt();
int m_max = m_timer_max_str.toInt();
int s_max = s_timer_max_str.toInt();
int max_value = m_max*60 + s_max; //整首歌有幾秒
int set_value = m_set*60 + s_set; //正播到第幾秒
ui->progressBar->setValue(set_value);
ui->progressBar->setMaximum(max_value);


}

加上音量控制,還發現只要把串流加到xmms2,就可聽線上廣播(下一版的重點).


read more...

2009年6月17日 星期三

用Qt寫的,初步堪用xmms2的播放介面.

據續上篇,終於初步完成堪用的xmms2播放介面(要先安裝xmms2,才能用,我只是用Qt去執行xmms2的指令),還有BUG要解,若是列表沒音樂按播放會關掉視窗,若是當按或目錄有空格用xmms2 add加不上列表,還有介面太醜要美化.
mainwindow.cpp程式碼(部落格因為不能顯示<>很麻煩,將程式碼放到下面超連結)

http://sites.google.com/site/yplinshouye/Home/xmms2_gui

執行結果:



read more...

2009年6月14日 星期日

QTreeWidgetItem取得上層(parent)的item text

QTreeWidgetItem要取得上一層的item text可用parent()這個函式,下面寫了好幾個方法都可取得,若要從目前這層取得到最上層只要一直parent(),用迴圈,讓後判斷是否是最上層既可,若是檔案tree,就能取得full path.

void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem* item, int column)

{
QString str1 = item->text(1); //取得第2欄text
QString str0 = item->text(0); //取得第1欄text
//QString str0 = ui->treeWidget->selectedItems().value(0)->text(0);//取得第1欄text
//QString str0 = ui->treeWidget->currentItem()->text(0); //取得第1欄text
//QString key = ui->treeWidget->currentItem()->parent()->text(0);//取得上層第1欄text
QString key = item->parent()->text(0);//取得上層第1欄text
QDir dir;
QString str2 = dir.filePath(key);
ui->listWidget->addItem(key); //把字串加到listWidget
}

下面就是一個取得檔案tree的full path,當我doubleclick,就能獲得item的檔案路徑.
QFileInfo fileInfo("/home/yplin66/qt");我是從qt目錄開展開.
只要判斷取得item text是否等於"qt",就應該終止迴圈,每取得一次text,就加到前面去,最後就是整個路徑了.

void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem* item, int column)
{
//QString str1 = item->text(1); //取得第2欄text
//QString str0 = item->text(0); //取得第1欄text
//QString str0 = ui->treeWidget->selectedItems().value(0)->text(0);//取得第1欄text
//QString str0 = ui->treeWidget->currentItem()->text(0);//取得第1欄text
//QString key = ui->treeWidget->currentItem()->parent()->text(0);//取得上層第1欄text
QString key; //QTreeWidgetItem item text
QString full_path; //檔案路徑
key = item->text(0);
full_path=key+"/";
while (key != "qt")
{
item=item->parent();
//取得上1層item
key = item->text(0); //取得上1層第1欄text
full_path=key+"/"+full_path;
}
ui->listWidget->addItem(full_path); //把字串加到listWidget
}
執行結果:(當然我最終是要獲得目錄下,所有檔案,加到list上,待續..)














終於寫完了,double click會把目錄下的檔案加到右邊的listWidget.(再來就來寫撥放音樂檔案)

void MainWindow::on_treeWidget_itemDoubleClicked(QTreeWidgetItem* item, int column)
{
//QString str1 = item->text(1); //取得第2欄text
//QString str0 = item->text(0); //取得第1欄text
//QString str0 = ui->treeWidget->selectedItems().value(0)->text(0);//取得第1欄text
//QString str0 = ui->treeWidget->currentItem()->text(0);//取得第1欄text
//QString key = ui->treeWidget->currentItem()->parent()->text(0);//取得上層第1欄text
QString key; //QTreeWidgetItem item text
QString full_path; //檔案路徑
key = item->text(0);
full_path=key+"/";
while (key != "qt")
{
item=item->parent(); //取得上1層item
key = item->text(0); //取得上1層第1欄text
full_path=key+"/"+full_path;

}
full_path="/home/yplin66/"+full_path;
QDir dir;
dir.setPath(full_path); //設到指定path
dir.setFilter(QDir::Files | QDir::NoSymLinks); //過濾檔案,目錄去掉
const QFileInfoList fileList = dir.entryInfoList(); //檔案資訊List
QFileInfo fileInfo(full_path);
QStringList fileColumn;
for (int i = 2; i < fileList.size(); i++) //0,1指. , ..故略過,一直到幾個檔案為止
{

fileInfo = fileList.at(i); //取得檔名
fileColumn.append(fileInfo.fileName()); //把檔名加到QStringList
;
}
ui->listWidget->clear();
ui->listWidget->addItems(fileColumn);//把QStringList加到listWidget

//ui->listWidget->addItem(full_path); //把字串加到listWidget
}


執行結果:


read more...

2009年6月13日 星期六

解決QT4.5.1無法在debian5.0編譯的問題

之前Qt4.5.1都是在ubuntu9.04下運行,沒問題,今天試一下debian5.0竟然不行Compiler,後來才發現,


因為少了安裝很多開發套件,只要裝上去就好了,每compiler一次就會說少那一個套件,竹一樁上去就可

,我是用Qt creator下compiler,然後Compile Out會有說少哪個套件.


cannot find -lSM

就是少libSM-dev(search libSM就找到了),反正就在l開頭後面插入ib這2個字

cannot fin -lXext就找libXext


這張是已經完成compiler了.(Compile Out)




read more...