label->setText(tr("<style>a{text-decoration: none}</style><a style='color: #09A3DC;' href=\"http://www.baidu.com\">baidu</a>"));
label->setTextFormat(Qt::RichText);
label->setOpenExternalLinks(true);
要记得加 "http://"
最开始没有加,怎么也打不开,呵呵。
const QUrl url(tr("http://www.baidu.com"));
QDesktopServices::openUrl(url);
只要继承这个ui类,生成的窗体就是无边框的。
虚函数: virtual QWidget * m_pGetDragnWidget()=0; 返回的就是鼠标可以拖动窗体的部分。
#ifndef MOVEABLEFRAMELESSWINDOW_H
#define MOVEABLEFRAMELESSWINDOW_H
#include <QObject>
#include <QDialog>
typedef enum {
eNone,
eTop = 0x01,
eRight = 0x02,
eBottom = 0x04,
eLeft = 0x08,
eTopLeft = 0x09,
eTopRight = 0x03,
eBottomLeft = 0x0C,
eBottomRight = 0x06
} EnumDirection;
class MoveableFramelessWindow : public QDialog
{
Q_OBJECT
public:
explicit MoveableFramelessWindow(bool bIsFixedWindow, QWidget *parent=0);
void m_vSetValueDir(int iValueDir);
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *);
void changeEvent(QEvent *e);
/**
* @brief get the widget which can be draged.
* @return
*/
virtual QWidget * m_pGetDragnWidget()=0;
/**
* @brief judge whether the mouse pressed position is in widget's rect
* @param widget
* @param point
* @return
*/
bool m_bIsPointInDragnWidget(const QWidget * widget, const QPoint &point);
protected slots:
void slot_vTitleMinBtn_clicked();
void slot_vTitleMaxBtn_clicked();
void slot_vTitleCloseBtn_clicked();
private:
enum EnumMousePressed {eNoPressed, eInBorderPressed, eNotInBorderPressed};
/**
* @brief judge the mouse direction
* @param mouse pos x
* @param mouse pos y
* @param rect Width
* @param rect Height
* @return the direction of mouse
*/
EnumDirection m_ePointValid(int x, int y, int iWidth, int iHeight);
/**
* @brief when mouse hover in border, change the mouse style
* @param eDirection
*/
void m_vSetCursorStyle(EnumDirection eDirection);
/**
* @brief drag the window in the eDirection direction
* @param iGlobalX: mouse pos x
* @param iGlobalY: mouse pos y
* @param eDirection
*/
void m_vSetDrayMove(int iGlobalX, int iGlobalY, EnumDirection eDirection);
EnumMousePressed m_eLeftMousePressed;
QPoint m_LeftMousePressedPoint;
QPoint m_LeftMouseMovedPoint;
EnumDirection m_eDirection;
bool m_bIsMaxWindow;
QRect m_locationRect;
bool m_bIsFixedWindow;
int VALUE_DIS;
};
#endif // MOVEABLEFRAMELESSWINDOW_H
#include <QtGui>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QRect>
#include <QPoint>
#include <QGridLayout>
#include "moveableframelesswindow.h"
#include <iostream>
using namespace std;
MoveableFramelessWindow::MoveableFramelessWindow(bool bIsFixedWindow, QWidget *parent) :
QDialog(parent)
{
//produces a borderless window
this->setWindowFlags(Qt::FramelessWindowHint);
//translucent background
//setAttribute(Qt::WA_TranslucentBackground);
m_eLeftMousePressed = eNoPressed;
m_eDirection = eNone;
//judge whether the window can change the size
m_bIsFixedWindow = bIsFixedWindow;
m_bIsMaxWindow = false;
VALUE_DIS = 10;
this->setWindowState( Qt::WindowNoState );
}
void MoveableFramelessWindow::mousePressEvent(QMouseEvent *e)
{
bool bMouseIsInDragnWidget = m_bIsPointInDragnWidget(m_pGetDragnWidget(), e->pos());
if(e->button() == Qt::LeftButton && bMouseIsInDragnWidget)
{
if( e->y()<VALUE_DIS || rect().height()-e->y()<VALUE_DIS ||
e->x()<VALUE_DIS || rect().width()-e->x()<VALUE_DIS )
{
m_eLeftMousePressed = eInBorderPressed;
}
else
{
m_eLeftMousePressed = eNotInBorderPressed;
}
m_LeftMousePressedPoint = e->globalPos();
e->accept();
}
e->ignore();
}
void MoveableFramelessWindow::mouseMoveEvent(QMouseEvent *e)
{
if(m_eLeftMousePressed == eNotInBorderPressed)
{
if( !m_bIsMaxWindow && (e->buttons() && Qt::LeftButton))
{
m_LeftMouseMovedPoint = e->globalPos();
this->move(this->pos() + m_LeftMouseMovedPoint - m_LeftMousePressedPoint);
m_LeftMousePressedPoint = m_LeftMouseMovedPoint;
e->accept();
}
}
else if(m_eLeftMousePressed == eInBorderPressed)
{
int iGlobalX = e->globalX();
int iGlobalY = e->globalY();
m_vSetDrayMove(iGlobalX, iGlobalY, m_eDirection);
m_LeftMousePressedPoint = QPoint(iGlobalX, iGlobalY);
}
else if( ! m_bIsFixedWindow)
{
m_eDirection = m_ePointValid(e->x(), e->y(), rect().width(), rect().height());
//m_bIsMouseNotInBorder = (m_eDirection == eNone) ;
m_vSetCursorStyle(m_eDirection);
}
}
void MoveableFramelessWindow::mouseReleaseEvent(QMouseEvent *)
{
m_eLeftMousePressed = eNoPressed;
m_eDirection = eNone;
m_vSetCursorStyle(m_eDirection);
}
bool MoveableFramelessWindow::m_bIsPointInDragnWidget(const QWidget *widget, const QPoint &point)
{
QRect rect = widget->rect();
if(point.x() >= rect.left() &&
point.x() <= rect.right() &&
point.y() >= rect.top() &&
point.y() <= rect.bottom())
{
return true;
}
else
{
return false;
}
}
EnumDirection MoveableFramelessWindow::m_ePointValid(int x, int y, int iWidth, int iHeight)
{
//Top Left
if(x <= VALUE_DIS && y <= VALUE_DIS)
{
return eTopLeft;
}
//Top Right
else if((x <= iWidth) && (x >= (iWidth-VALUE_DIS)) && y <= VALUE_DIS)
{
return eTopRight;
}
//Bottom Left
else if(x <= VALUE_DIS && (y <= iHeight) && (y >= (iHeight-VALUE_DIS)))
{
return eBottomLeft;
}
//Bottom Right
else if((x <= iWidth) && (x >= (iWidth-VALUE_DIS)) && (y <= iHeight) && (y >= (iHeight-VALUE_DIS)))
{
return eBottomRight;
}
//Top
else if((x <= (iWidth-VALUE_DIS)) && (x >= VALUE_DIS) && y <= VALUE_DIS)
{
return eTop;
}
//Right
else if((x <= iWidth) && (x >= (iWidth-VALUE_DIS)) && (y <= (iHeight-VALUE_DIS)) && (y >= VALUE_DIS))
{
return eRight;
}
//Bottom
else if((x <= (iWidth-VALUE_DIS)) && (x >= VALUE_DIS) && (y <= iHeight) && (y >= (iHeight-VALUE_DIS)))
{
return eBottom;
}
//Left
else if(x <= VALUE_DIS && (y <= (iHeight-VALUE_DIS)) && (y >= VALUE_DIS))
{
return eLeft;
}
else
{
return eNone;
}
}
void MoveableFramelessWindow::m_vSetCursorStyle(EnumDirection eDirection)
{
switch(eDirection)
{
case eTop:
case eBottom:
setCursor(Qt::SizeVerCursor);
break;
case eLeft:
case eRight:
setCursor(Qt::SizeHorCursor);
break;
case eTopRight:
case eBottomLeft:
setCursor(Qt::SizeBDiagCursor);
break;
case eTopLeft:
case eBottomRight:
setCursor(Qt::SizeFDiagCursor);
break;
case eNone:
default:
setCursor(Qt::ArrowCursor);
break;
}
}
void MoveableFramelessWindow::m_vSetDrayMove(int iGlobalX, int iGlobalY, EnumDirection eDirection)
{
int iDx = iGlobalX - m_LeftMousePressedPoint.x();
int iDy = iGlobalY - m_LeftMousePressedPoint.y();
QRect rectWindow = geometry();
if(eDirection & eTop)
{
rectWindow.setTop(rectWindow.top() + iDy);
}
if(eDirection & eRight)
{
rectWindow.setRight(rectWindow.right() + iDx);
}
if(eDirection & eBottom)
{
rectWindow.setBottom(rectWindow.bottom() + iDy);
}
if(eDirection & eLeft)
{
rectWindow.setLeft(rectWindow.left() + iDx);
}
if(rectWindow.width() < minimumWidth() || rectWindow.width() > maximumWidth() ||
rectWindow.height() < minimumHeight() || rectWindow.height() > maximumHeight())
{
return ;
}
setGeometry(rectWindow);
}
void MoveableFramelessWindow::slot_vTitleMinBtn_clicked()
{
this->showMinimized();
}
void MoveableFramelessWindow::slot_vTitleMaxBtn_clicked()
{
this->setWindowState( m_bIsMaxWindow ? Qt::WindowNoState : Qt::WindowMaximized );
m_bIsMaxWindow = !m_bIsMaxWindow;
}
void MoveableFramelessWindow::slot_vTitleCloseBtn_clicked()
{
qApp->exit();
}
void MoveableFramelessWindow::m_vSetValueDir(int iValueDir)
{
VALUE_DIS = iValueDir;
}
void MoveableFramelessWindow::changeEvent(QEvent *e)
{
switch(e->type())
{
case QEvent::WindowStateChange:
this->repaint();
e->ignore();
}
}
把下载的文件解压之后会生成两个文件 cpp11.vim 和 cpp11_cbase.vim。
然后把这两个文件复制到 ~/.vim/syntax 目录下面,如果没有这个目录的话就自己手动建立一个。
你也可以自己修改语法的颜色定义, 在cpp11_cbase.vim 中就可以修改了。
最后还要在 .vimrc 中加一句话:
au BufNewFile,BufRead .cpp,.c set syntax=cpp11
将 .vimrc 文件复制到 ~ 目录下就可以了。
" vim common cmd
" ci[ delete character between [] and enter insert mode.
" ci( delete character between () and enter insert mode.
" ci{ delete character between {}and enter insert mode.
" ci< delete character between <> and enter insert mode.
" note: ci-->ca, it will delete [],(),{},<>.
" if you just want to select the character, use ci-->vi instead.
"
" gg=G format the code.
"global function
function! GetSys()
if has("win16") || has("win32") || has("win64") || has("win95")
return "windows"
elseif has("unix")
return "linux"
endif
endfunction
" for taglist
""""""""""""""""""""""""""""""""""""""""""
":Tlist open taglist
":TlistToggle open taglist
let Tlist_Ctags_Cmd='/usr/bin/ctags'
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1
set tags+=/usr/include/tags
set tags+=/usr/local/include/tags
set tags+=/root/unpv13e/tags
set tags+=/root/NetVol1/working-branch/tags
set tags+=/root/git/JCL/branches/working-branch/tags
nnoremap <silent><F4> :TlistToggle<CR>
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
if exists("tags")
set tags+=./tags
endif
"title
""""""""""""""""""""""""""""""""""""""""""
set title
set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:.:h\")})%)%(\ %a%)
set titlestring=%F
"status bar
""""""""""""""""""""""""""""""""""""""""""
set laststatus=2 "(default is 1, will not display status bar. set to 2 will display status bar)
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
set statusline=
set statusline+=%-3.3n\ "buffer number
set statusline+=%f\ "filename
set statusline+=%h%m%r%w "status flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}] "filetype
set statusline+=%= "right align remainder
set statusline+=0x%-8B "character value
set statusline+=%-14(%l,%c%V%) "line, character
set statusline+=%<%P "file position
"cmd bar
""""""""""""""""""""""""""""""""""""""""""
set showcmd " Show (partial) command in status line.
set showmode
set cmdheight=1
"fold
""""""""""""""""""""""""""""""""""""""""""
set foldenable
set foldmethod=syntax "index, expr, marker, syntax, diff
"set foldclose=all
" use space to folden, zo:open the fold, zc:fold.
nnoremap <space> @=((foldclosed(line( '.' ))<0) ? 'zc' : 'zo')<CR>
set foldopen-=search "don't open folds when I search
set foldopen-=undo "don't open folds when I undo
set foldlevel=100 "don't folds when I open the file
"set foldcolumn=1 "set the fold column width
"Linebreak on 500 characters
""""""""""""""""""""""""""""""""""""""""""
set tw=500
set lbr
set fo+=mB "support for chinese.
"common
""""""""""""""""""""""""""""""""""""""""""
if has("syntax")
syntax enable
syntax on
endif
if has('mouse')
set mouse=a " Enable mouse usage (all modes)
endif
filetype plugin on
filetype indent on
set autoread "set to auto read when a file is changed from the outside.
set ambiwidth=double "for some unicode special character.
set whichwrap=b,s,<,>,[,]
set nocompatible "close vi compatible mode
set backspace=indent,eol,start
set history=100
set cursorline "current line will have a underline.
set hlsearch " hight light search
set number
set ruler "display cursor position in the right corner of the vim window
set magic "set magic on, for regular expression
set noautochdir
set nocompatible " Use Vim defaults
set ignorecase " ignore case
set incsearch " display when you still typing
set wrapscan " stop the scan at the end of file
set wrap
set hidden
set vb t_vb= "close the voice when cmd error.
" Show autocomplete menus.
set wildmenu
" Minimal number of screen lines to keep above and below the cursor.
"set scrolloff=999
"map
""""""""""""""""""""""""""""""""""""""""""
"Command Normal Visual OperatorPending InsertOnly CommandLine
":map y y y
":nmap y
":vmap y
":omap y
":map! y y
":imap y
":cmap y
""""""""""""""""""""""""""""""""""""""""""
":h key-notation to see vim help document.
":map to list all key map.
"<Esc> stand for Escape
"<CR> stand for Enter
"<Space> <Tab>
"<C-Esc> stand for Ctrl-Esc
"<C-G> stand for Ctrl-G
"<C-LeftMouse> Ctrl+mouse left clicked.
"<S-F1> stand for Shift-F1
"<M-key> or <A-key> stand for Alt
""""""""""""""""""""""""""""""""""""""""""
"<F1>, <F11> can't be use
"<F1> is the ubuntu help dialog.
"<F11> is the ubuntu console maximum
"set mapleader
let mapleader="," "mapleader default is '/', <leader> is mapleader.
let g:mapleader=","
"use ,s to source .vimrc
map <silent> <leader>s :source ~/.vimrc<CR>
"use ,e to open .vimrc
map <silent> <leader>e :e ~/.vimrc<CR>
"auto source .vimrc after edit .vimrc
autocmd! bufwritepost .vimrc source ~/.vimrc
"use , to remove highlight search
nmap <silent> <leader><CR> :noh<CR>
nmap <leader>w :w!<cr>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
map <leader>v :vsplit<CR>
map <C-A> ggvGY
map! <C-A> <Esc>ggvGY
map <F2> <Esc>:tabnew<CR>
map <C-P> :tabprev<CR>
map <C-N> :tabnext<CR>
map <C-C> :tabclose<CR>
"nnoremap <F3> :g/^\s*$/d<CR> "this will delete all blank line in file.
"map <C-H> :hide<CR>
"map <C-J> :tn<CR>
"map <C-K> :tp<CR>
"map <C-L> :cd .<CR>
map \p i(<Esc>ea)<Esc>
map \c i{<Esc>ea}<Esc>
map \n :nohlsearch<CR>
nmap <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
imap <F3> <C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
map <F5> :set ts=4<CR>:set expandtab<CR>:%retab!<CR>
map <C-F5> :set ts=4<CR>:set noexpandtab<CR>:%retab!<CR>
"if no !, just replace first TAB of each line.
map <F7> ggO/*<CR><Esc>0d$I * Copyright(c) 2016 ShaXian MDGSF.<CR><Esc>0d$I *<CR><Esc>0d$I * Authored by MDGSF on:<Esc>:read !date <CR>kJ$a<CR><Esc>0d$I *<CR><Esc>0d$I * @desc:<CR><Esc>0d$I *<CR><Esc>0d$I * @history:<CR><Esc>0d$I */<Esc>
map <F8> O/*<CR><Esc>0d$I * Copyright(c) 2016 ShaXian MDGSF.<CR><Esc>0d$I * Authored by MDGSF on:<Esc>:read !date <CR>kJ$a<CR><Esc>0d$I * Function:<CR><Esc>0d$I * @param<CR><Esc>0d$I * @return:<CR><Esc>0d$I */<Esc>
"indent
""""""""""""""""""""""""""""""""""""""""""
"set expandtab "tab will auto changed to blank space, (Ctrl+V+tab will input real tab), Makefile command need tab.
set smartindent " (set si)
set smarttab
set tabstop=4 " tab stop (set ts=4)
set shiftwidth=4 " shift width
set softtabstop=4
set autoindent " auto indent (set ai)
set wrap "Wrap lines
"auto complete
":inoremap ( ()<Esc>i
":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {}<Esc>i
":inoremap } <c-r>=ClosePair('}')<CR>
":inoremap [ []<Esc>i
":inoremap ] <c-r>=ClosePair(']')<CR>
":inoremap " ""<Esc>i
":inoremap ' ''<Esc>i
"function! ClosePair(char)
" if getline('.')[col('.') - 1] == a:char
" return "\<Right>"
" else
" return a:char
" endif
"endfunction
"
""open cpp and text at the same time,
""{ will not like you want.
""for c/c++
"function! InitC()
" set cindent
" set cino=:0g0t0(sus
" inoremap { {<CR>}<Esc>ko
"endfunction
"autocmd! Filetype c,cpp,h,hpp :call InitC()
"au! BufNewFile,BufRead c,cpp,h,hpp :call InitC()
"for text
autocmd! FileType text :call InitText()
function! InitText()
setlocal textwidth=78
"inoremap { {}<Esc>i
endfunction
"for html
au FileType html setlocal autoindent indentexpr=
""""""""""""""""""""""""""""""""""""""""""
" BufExplorer
""""""""""""""""""""""""""""""""""""""""""
",bv
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
let g:bufExplorerSortBy="mru"
let g:bufExplorerSplitRight=0
let g:bufExplorerSplitVertical=1
let g:bufExplorerSplitVertSize=30
let g:bufExplorerUseCurrentWindow=1
autocmd BufWinEnter \[Buf\ List\] setl nonumber
""""""""""""""""""""""""""""""""""""""""""
" Nerd tree
""""""""""""""""""""""""""""""""""""""""""
map <F10> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
""""""""""""""""""""""""""""""""""""""""""
" a.vim
""""""""""""""""""""""""""""""""""""""""""
":A switches to the header file corresponding to the current file being edited (or vise versa)
":AS splits and switches
":AV vertical splits and switches
":AT new tab and switches
":AN cycles through matches
":IH switches to file under cursor
":IHS splits and switches
":IHV vertical splits and switches
":IHT new tab and switches
":IHN cycles through matches
"<Leader>ih switches to file under cursor
"<Leader>is switches to the alternate file of file under cursor (e.g. on <foo.h> switches to foo.cpp)
"<Leader>ihn cycles through matches
nnoremap ;z :A<CR>
"for windows and gui
if (has("win32"))
if (has("gui_running"))
set guifont=Bitstream_Vera_Sans_Mono:h9:cANSI
set guifontwide=NSimSun:h9:cGB2312
"hide gui
"set guioptions-=m "remove menu bar
set guioptions-=T "remove tool bar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=l "remove left-hand scroll bar
set guioptions-=L "remove left-hand scroll bar even if there is a vertical split
set guioptions-=b "remove bottom scroll bar
endif
else
if (has("gui_running"))
set guifont=Bitstream\ Vera\ Sans\ Mono\ 9
endif
endif
if GetSys() == "windows"
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5
set encoding=utf-8
set langmenu=zh_CN.UTF-8
language message zh_CN.UTF-8
set nowrap
colo torte
endif
function! ToggleSyntax()
if(exists("g:syntax_on"))
syntax off
else
syntax enable
endif
endfunction
nmap <silent> ;s :call ToggleSyntax()<CR>
function! CapitalizeCenterAndMoveDown()
s/\<./\u&/g
center
+1
endfunction
nmap <silent> ;c :call CapitalizeCenterAndMoveDown()<CR>
function! CurrentLineLength()
let len = strlen(getline("."))
return len
endfunction
""""""""""""""""""""""""""""""""""""""""""
":help vim-script-intro
":help keycodes
":help functions
":help function-list
"let count = 1
"let s:count = 1 s: means count is a local variable.
If there is no VBoxGuestAddition.iso, go to the vbox installed directory.
click the Auto-mount and fixed allocation.
Remember to restart the ubuntu, or maybe it can’t be used.
sudo mkdir /mnt/shared
sudo mount -t vboxsf share /mnt/shared
sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
And after that, if you want to get root, do as follows:
su root
Password:
apt-get install vim
sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eht0 inet static
address 172.17.92.238
netmask 255.255.255.0
gateway 172.17.92.110
sudo vim /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.8
sudo /etc/init.d/networking restart
vim ~/.bashrc
alias ls='ls --color=auto'
alias f='fg'
alias j='jobs'
source ~/.bashrc
apt-get update
apt-get upgrade
apt-get install g++
apt-get install gdb
apt-get install openssh-server
sudo service ssh start (must use sudo even you are root)
ps -e | grep sshd
apt-get install ctags
apt-get install samba
apt-get install git
apt-get install subversion