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项中可以有多列数据,每列数据都可以设 ...
随机推荐
- 刚装完Linux就CPU占用率高
top命令发现如下三个进程占据了前三的CPU使用率 wpa_supplicant NetworkManager rsyslogd google发现前两个进程与无线网络有关,我的电脑是笔记本,插的有线, ...
- 《转》python基础下
转自http://www.cnblogs.com/BeginMan/archive/2013/04/12/3016323.html 一.数字 在看<Python 核心编程>的时候,我就有点 ...
- jdbc出现中文乱码的解决办法
- linux下创建oracle表空间
来自:http://blog.sina.com.cn/s/blog_62192aed01018aep.html 1 . 登录服务器 2 . 查看磁盘空间是否够大df -h -h更具目前磁盘空间和使用情 ...
- 5个CSS3技术实现设计增强
层叠样式表(css)是Web设计的一种语言,CSS的下一代版本CSS3已经蓄势待发.你是否可望开始使用它们却又不知从何下手呢?虽然还有一些新属性没有得到官方的确认,但是一些浏览器已经开始支持来自CSS ...
- 21-2-substring
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Mysql: [Warning] Using a password on the command line interface can be insecure
mysql: [Warning] Using a password on the command line interface can be insecure MySQL 5.6 警告信息 comma ...
- 一图读懂POLARDB Box数据库一体机的云原生力量!
2019杭州云栖大会上,阿里云宣布正式推出高性能数据库一体机——POLARDB Box,用户部署在自有数据中心即可享受云数据库的便捷体验,同时还为Oracle等传统数据库用户提供一键迁移功能,最多节省 ...
- SP1296 SUMFOUR - 4 values whose sum is 0
传送门 解题思路 四个数组一起做有点炸.先把他们合并成两个数组,然后让一个数组有序,枚举另一个数组的元素,二分即可.时间复杂度\(O(n^2logn^2)\) 代码 #include<iostr ...
- P1934 封印
P1934 封印 题目描述 很久以前,魔界大旱,水井全部干涸,温度也越来越高.为了拯救居民,夜叉族国王龙溟希望能打破神魔之井,进入人界“窃取”水灵珠,以修复大地水脉.可是六界之间皆有封印,神魔之井的封 ...