Extjs4 desktop 图标自动换行,横纵排列 图标大小修改
一、图标换行
/*!
* Ext JS Library 4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/ /**
* @class Ext.ux.desktop.Desktop
* @extends Ext.panel.Panel
* <p>This class manages the wallpaper, shortcuts and taskbar.</p>
*/
Ext.define('Ext.ux.desktop.Desktop', {
extend: 'Ext.panel.Panel', alias: 'widget.desktop', uses: [
'Ext.util.MixedCollection',
'Ext.menu.Menu',
'Ext.view.View', // dataview
'Ext.window.Window', 'Ext.ux.desktop.TaskBar',
'Ext.ux.desktop.Wallpaper'
], activeWindowCls: 'ux-desktop-active-win',
inactiveWindowCls: 'ux-desktop-inactive-win',
lastActiveWindow: null, border: false,
html: ' ',
layout: 'fit', xTickSize: 1,
yTickSize: 1, app: null, /**
* @cfg {Array|Store} shortcuts
* The items to add to the DataView. This can be a {@link Ext.data.Store Store} or a
* simple array. Items should minimally provide the fields in the
* {@link Ext.ux.desktop.ShorcutModel ShortcutModel}.
*/
shortcuts: null, /**
* @cfg {String} shortcutItemSelector
* This property is passed to the DataView for the desktop to select shortcut items.
* If the {@link #shortcutTpl} is modified, this will probably need to be modified as
* well.
*/
shortcutItemSelector: 'div.ux-desktop-shortcut', /**
* @cfg {String} shortcutTpl
* This XTemplate is used to render items in the DataView. If this is changed, the
* {@link shortcutItemSelect} will probably also need to changed.
*/
shortcutTpl: [
'<tpl for=".">',
'<div class="ux-desktop-shortcut" id="{name}-shortcut">',
'<div class="ux-desktop-shortcut-icon {iconCls}">',
'<img src="',Ext.BLANK_IMAGE_URL,'" title="{name}">',
'</div>',
'<span class="ux-desktop-shortcut-text">{name}</span>',
'</div>',
'</tpl>',
'<div class="x-clear"></div>'
], /**
* @cfg {Object} taskbarConfig
* The config object for the TaskBar.
*/
taskbarConfig: null, windowMenu: null, initComponent: function () {
var me = this;
me.windowMenu = new Ext.menu.Menu(me.createWindowMenu()); me.bbar = me.taskbar = new Ext.ux.desktop.TaskBar(me.taskbarConfig);
me.taskbar.windowMenu = me.windowMenu; me.windows = new Ext.util.MixedCollection(); me.contextMenu = new Ext.menu.Menu(me.createDesktopMenu()); me.items = [
{ xtype: 'wallpaper', id: me.id+'_wallpaper' },
me.createDataView()
]; me.callParent(); me.shortcutsView = me.items.getAt(1);
me.shortcutsView.on('itemclick', me.onShortcutItemClick, me); var wallpaper = me.wallpaper;
me.wallpaper = me.items.getAt(0);
if (wallpaper) {
me.setWallpaper(wallpaper, me.wallpaperStretch);
}
}, afterRender: function () {
var me = this;
me.callParent();
me.el.on('contextmenu', me.onDesktopMenu, me);
// 实现桌面图标自动换行
Ext.Function.defer(me.initShortcut, 1);
}, //------------------------------------------------------
// Overrideable configuration creation methods createDataView: function () {
var me = this;
return {
xtype: 'dataview',
overItemCls: 'x-view-over',
trackOver: true,
itemSelector: me.shortcutItemSelector,
store: me.shortcuts,
style: {
position: 'absolute'
},
x: 0, y: 0,
// 实现桌面图标自动换行
listeners:{
resize:me.initShortcut
},
tpl: new Ext.XTemplate(me.shortcutTpl)
};
}, createDesktopMenu: function () {
var me = this, ret = {
items: me.contextMenuItems || []
}; if (ret.items.length) {
ret.items.push('-');
} ret.items.push(
{ text: '展开', handler: me.tileWindows, scope: me, minWindows: 1 },
{ text: '层叠', handler: me.cascadeWindows, scope: me, minWindows: 1 }) return ret;
}, createWindowMenu: function () {
var me = this;
return {
defaultAlign: 'br-tr',
items: [
{ text: '恢复', handler: me.onWindowMenuRestore, scope: me },
{ text: '最小化', handler: me.onWindowMenuMinimize, scope: me },
{ text: '最大化', handler: me.onWindowMenuMaximize, scope: me },
'-',
{ text: '关闭', handler: me.onWindowMenuClose, scope: me }
],
listeners: {
beforeshow: me.onWindowMenuBeforeShow,
hide: me.onWindowMenuHide,
scope: me
}
};
}, //------------------------------------------------------
// Event handler methods onDesktopMenu: function (e) {
var me = this, menu = me.contextMenu;
e.stopEvent();
if (!menu.rendered) {
menu.on('beforeshow', me.onDesktopMenuBeforeShow, me);
}
menu.showAt(e.getXY());
menu.doConstrain();
}, onDesktopMenuBeforeShow: function (menu) {
var me = this, count = me.windows.getCount(); menu.items.each(function (item) {
var min = item.minWindows || 0;
item.setDisabled(count < min);
});
}, onShortcutItemClick: function (dataView, record) {
var me = this, module = me.app.getModule(record.data.module),
win = module && module.createWindow(); if (win) {
me.restoreWindow(win);
}
}, onWindowClose: function(win) {
var me = this;
me.windows.remove(win);
me.taskbar.removeTaskButton(win.taskButton);
me.updateActiveWindow();
}, //------------------------------------------------------
// Window context menu handlers onWindowMenuBeforeShow: function (menu) {
var items = menu.items.items, win = menu.theWin;
items[0].setDisabled(win.maximized !== true && win.hidden !== true); // Restore
items[1].setDisabled(win.minimized === true); // Minimize
items[2].setDisabled(win.maximized === true || win.hidden === true); // Maximize
}, onWindowMenuClose: function () {
var me = this, win = me.windowMenu.theWin; win.close();
}, onWindowMenuHide: function (menu) {
Ext.defer(function() {
menu.theWin = null;
}, 1);
}, onWindowMenuMaximize: function () {
var me = this, win = me.windowMenu.theWin; win.maximize();
win.toFront();
}, onWindowMenuMinimize: function () {
var me = this, win = me.windowMenu.theWin; win.minimize();
}, onWindowMenuRestore: function () {
var me = this, win = me.windowMenu.theWin; me.restoreWindow(win);
}, //------------------------------------------------------
// Dynamic (re)configuration methods getWallpaper: function () {
return this.wallpaper.wallpaper;
}, setTickSize: function(xTickSize, yTickSize) {
var me = this,
xt = me.xTickSize = xTickSize,
yt = me.yTickSize = (arguments.length > 1) ? yTickSize : xt; me.windows.each(function(win) {
var dd = win.dd, resizer = win.resizer;
dd.xTickSize = xt;
dd.yTickSize = yt;
resizer.widthIncrement = xt;
resizer.heightIncrement = yt;
});
}, setWallpaper: function (wallpaper, stretch) {
this.wallpaper.setWallpaper(wallpaper, stretch);
return this;
}, //------------------------------------------------------
// Window management methods cascadeWindows: function() {
var x = 0, y = 0,
zmgr = this.getDesktopZIndexManager(); zmgr.eachBottomUp(function(win) {
if (win.isWindow && win.isVisible() && !win.maximized) {
win.setPosition(x, y);
x += 40;
y += 40;
}
});
}, createWindow: function(config, cls) {
var me = this, win, cfg = Ext.applyIf(config || {}, {
stateful: false,
isWindow: true,
constrainHeader: true,
minimizable: true,
maximizable: true
}); cls = cls || Ext.window.Window;
win = me.add(new cls(cfg)); me.windows.add(win); win.taskButton = me.taskbar.addTaskButton(win);
win.animateTarget = win.taskButton.el; win.on({
activate: me.updateActiveWindow,
beforeshow: me.updateActiveWindow,
deactivate: me.updateActiveWindow,
minimize: me.minimizeWindow,
destroy: me.onWindowClose,
scope: me
}); win.on({
boxready: function () {
win.dd.xTickSize = me.xTickSize;
win.dd.yTickSize = me.yTickSize; if (win.resizer) {
win.resizer.widthIncrement = me.xTickSize;
win.resizer.heightIncrement = me.yTickSize;
}
},
single: true
}); // replace normal window close w/fadeOut animation:
win.doClose = function () {
win.doClose = Ext.emptyFn; // dblclick can call again...
win.el.disableShadow();
win.el.fadeOut({
listeners: {
afteranimate: function () {
win.destroy();
}
}
});
}; return win;
}, getActiveWindow: function () {
var win = null,
zmgr = this.getDesktopZIndexManager(); if (zmgr) {
// We cannot rely on activate/deactive because that fires against non-Window
// components in the stack. zmgr.eachTopDown(function (comp) {
if (comp.isWindow && !comp.hidden) {
win = comp;
return false;
}
return true;
});
} return win;
}, getDesktopZIndexManager: function () {
var windows = this.windows;
// TODO - there has to be a better way to get this...
return (windows.getCount() && windows.getAt(0).zIndexManager) || null;
}, getWindow: function(id) {
return this.windows.get(id);
}, minimizeWindow: function(win) {
win.minimized = true;
win.hide();
}, restoreWindow: function (win) {
if (win.isVisible()) {
win.restore();
win.toFront();
} else {
win.show();
}
return win;
}, tileWindows: function() {
var me = this, availWidth = me.body.getWidth(true);
var x = me.xTickSize, y = me.yTickSize, nextY = y; me.windows.each(function(win) {
if (win.isVisible() && !win.maximized) {
var w = win.el.getWidth(); // Wrap to next row if we are not at the line start and this Window will
// go off the end
if (x > me.xTickSize && x + w > availWidth) {
x = me.xTickSize;
y = nextY;
} win.setPosition(x, y);
x += w + me.xTickSize;
nextY = Math.max(nextY, y + win.el.getHeight() + me.yTickSize);
}
});
}, updateActiveWindow: function () {
var me = this, activeWindow = me.getActiveWindow(), last = me.lastActiveWindow;
if (activeWindow === last) {
return;
} if (last) {
if (Ext.isEmpty(last.el)) { return; }; //增加这一行
if (last.el.dom) {
last.addCls(me.inactiveWindowCls);
last.removeCls(me.activeWindowCls);
}
last.active = false;
} me.lastActiveWindow = activeWindow; if (activeWindow) {
activeWindow.addCls(me.activeWindowCls);
activeWindow.removeCls(me.inactiveWindowCls);
activeWindow.minimized = false;
activeWindow.active = true;
} me.taskbar.setActiveButton(activeWindow && activeWindow.taskButton);
}, //hzm新增方法,应用于界面图标自动换行
initShortcut : function() {
var btnHeight = 64;
var btnWidth = 64;
var btnPadding = 30;
var col = {index : 1,x : btnPadding};
var row = {index : 1,y : btnPadding};
var bottom;
var numberOfItems = 0;
var taskBarHeight = Ext.query(".ux-taskbar")[0].clientHeight + 40;
var bodyHeight = Ext.getBody().getHeight() - taskBarHeight;
var bodyWidth = Ext.getBody().getWidth();
var items = Ext.query(".ux-desktop-shortcut"); //0:纵向,1:横向
var gravity = 1; //横向
if(gravity) {
for (var i = 0, len = items.length; i < len; i++) {
numberOfItems += 1;
right = col.x + btnWidth;
if (((bodyWidth < right) ? true : false) && right > (btnWidth + btnPadding)) {
numberOfItems = 0;
col = {index : 1, x : btnPadding};
row = {index : row.index++, y : row.y + btnHeight + btnPadding};
}
Ext.fly(items[i]).setXY([col.x, row.y]);
col.index++;
col.x = col.x + btnWidth + btnPadding;
}
} else {
for (var i = 0, len = items.length; i < len; i++) {
numberOfItems += 1;
bottom = row.y + btnHeight;
if (((bodyHeight < bottom) ? true : false) && bottom > (btnHeight + btnPadding)) {
numberOfItems = 0;
col = {index : col.index++,x : col.x + btnWidth + btnPadding};
row = {index : 1,y : btnPadding};
}
Ext.fly(items[i]).setXY([col.x, row.y]);
row.index++;
row.y = row.y + btnHeight + btnPadding;
}
}
}
});
二、图标大小修改 desktop.css文件
.ux-desktop-shortcut {
cursor: pointer;
text-align: center;
padding: 8px;
margin: 8px;
width: 64px;
}
.notepad-shortcut {
background-image: url(../images/notepadLarge.png);
width: 48px;
height: 48px;
}
Extjs4 desktop 图标自动换行,横纵排列 图标大小修改的更多相关文章
- UI图标不用愁:矢量字体图标Font-Awesome
Font-Awesome,这个项目主要是css3的一个应用,准确的说是一段css,这里的把很多图标的东西做到了font文件里面,然后通过引用外部font文件的方式,来展现图标. Font Awesom ...
- 阿里UX矢量图标库–最强大的矢量图标库(Icon font制作力荐工具)
继前面介绍过ICON-FONT的制作后,找了几个ICON库都是国外的今天偶然发现阿里巴巴的图标矢量库,www.iconfont.cn用了之后感觉很强大,丰富的图标库(集合阿里妈妈&淘宝的图标库 ...
- MFC修改任务栏图标及程序运行exe图标
修改左上角的图标和任务栏里图标 在对话框构造函数中 1 CTestDlg::CTestDlg(CWnd* pParent )2 : CDialog(CTestDlg::IDD, pParent)3 { ...
- 造excel表格横、列数据每一格自动累加填充效果
1.需求 excel每个横格子和竖格子number数据不一致的情况,保持如下金额字段每次自动累加 2.步骤: 1)设置excel格子为number格式(可以不要小数) 2)选中需要增序的单元格,选择e ...
- MUI框架-14-使用自定义icon图标、引入阿里巴巴矢量图标
MUI框架-14-使用自定义icon图标.引入阿里巴巴矢量图标 首先介绍介绍一下,前端必备的非常强大的 阿里巴巴矢量图标库:地址是:http://www.iconfont.cn/ 这里有丰富,精美,且 ...
- groupbox 下的datagridview的列标题字体修改混乱
groupbox 下的datagridview的列标题字体修改混乱
- SQLServer数据库自增长标识列的更新修改操作
SQLServer数据库自增长标识列的更新修改操作方法在日常的sql server开发中,经常会用到Identity类型的标识列作为一个表结构的自增长编号.比如文章编号.记录序号等等.自增长的标识列的 ...
- Oracle 表的行数、表占用空间大小,列的非空行数、列占用空间大小 查询
--表名,表占用空间大小(MB),行数select table_name, round(num_rows * avg_row_len /1024/1024, 8) as total_len, num_ ...
- PyQt(Python+Qt)学习随笔:QTreeWidgetItem项列图标的访问方法
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 树型部件QTreeWidget中的QTreeWidgetItem项中可以有多列数据,每列数据都可以设 ...
随机推荐
- Python分布式爬虫必学框架scrapy打造搜索引擎✍✍✍
Python分布式爬虫必学框架scrapy打造搜索引擎 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身 ...
- [USACO11OPEN]玉米田迷宫Corn Maze
题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...
- LightOJ 1245 - Harmonic Number (II)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1245 题意:仿照上面那题他想求这么个公式的数.但是递归太慢啦.让你找公式咯. ...
- callable接口的多线程实现方式
package com.cxy.juc; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionExce ...
- final修饰和StringBuffer的几个案例(拼接,反转,对称操作)
final关键字修饰时如果是基本数据类型的变量,则其数值一旦在初始化之后便不能更改:如果是引用类型的变量,则在对其初始化之后便不能再让其指向另一个对象,但引用变量不能变,引用变量所指向的对象中的内容还 ...
- Linux 实用指令(10)-RPM和YUM
目录 RPM 和 YUM 1 rpm 包的管理 1.1 介绍 1.2 rpm包的简单查询指令 1.3 rpm包名基本格式 1.4 rpm包的其他查询指令: 1.5 卸载rpm 包 1.6 安装rpm包 ...
- PHP算法之宝石与石头
给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...
- sql(10) sum
SUM() 函数SUM 函数返回数值列的总数(总额).SQL SUM() 语法SELECT SUM(column_name) FROM table_name新建表 StudentSS_id Grade ...
- Git 如何使用ssh上传或者同步/下载项目到github
上传本地代码及更新代码到GitHub教程 上传本地代码 第一步:去github上创建自己的Repository,创建页面如下图所示: 红框为新建的仓库的https地址 第二步: echo " ...
- [JZOJ3302] 【集训队互测2013】供电网络
题目 题目大意 给你一个有向图,每个点开始有一定的水量(可能为负数),可以通过边流到其它点. 每条边的流量是有上下界的. 每个点的水量可以增加或减少(从外界补充或泄出到外界),但是需要费用,和增加(减 ...